Skip to content

Commit 0c42ab0

Browse files
committed
test/system: Connect system tests to Meson
A bit of plumbing in the build files has been done to accommodate the change as much as possible. If we're to use meson.build in the 'test/system' subdir we better also install the data from there. This also adjust the CI playbooks to launch the tests via Meson by specifying the specific test suite ('system'). This change also means the test suite needs to be run from the 'test/system' subdirectory for the bats helper libraries to be discovered correctly. #1062
1 parent 7a44a81 commit 0c42ab0

File tree

6 files changed

+101
-35
lines changed

6 files changed

+101
-35
lines changed

meson.build

-28
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@ subid_dep = cc.find_library('subid', has_headers: ['shadow/subid.h'])
1919
go = find_program('go')
2020
go_md2man = find_program('go-md2man')
2121

22-
bats = find_program('bats', required: false)
2322
codespell = find_program('codespell', required: false)
24-
htpasswd = find_program('htpasswd', required: false)
25-
openssl = find_program('openssl', required: false)
26-
podman = find_program('podman', required: false)
2723
shellcheck = find_program('shellcheck', required: false)
28-
skopeo = find_program('skopeo', required: false)
2924

3025
bashcompletionsdir = get_option('bash_completions_dir')
3126
if bashcompletionsdir == ''
@@ -84,29 +79,6 @@ if shellcheck.found()
8479
test('shellcheck toolbox (deprecated)', shellcheck, args: [toolbox_sh])
8580
endif
8681

87-
install_subdir(
88-
'test',
89-
install_dir: get_option('datadir') / meson.project_name(),
90-
exclude_files: [
91-
'system/libs/bats-assert/.git',
92-
'system/libs/bats-assert/.gitignore',
93-
'system/libs/bats-assert/.travis.yml',
94-
'system/libs/bats-assert/package.json',
95-
'system/libs/bats-support/.git',
96-
'system/libs/bats-support/.gitignore',
97-
'system/libs/bats-support/.travis.yml',
98-
'system/libs/bats-support/package.json'
99-
],
100-
exclude_directories: [
101-
'system/libs/bats-assert/.git',
102-
'system/libs/bats-assert/script',
103-
'system/libs/bats-assert/test',
104-
'system/libs/bats-support/.git',
105-
'system/libs/bats-support/script',
106-
'system/libs/bats-support/test'
107-
]
108-
)
109-
11082
subdir('data')
11183
subdir('doc')
11284
subdir('profile.d')

playbooks/system-test.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
- include_tasks: build.yaml
2121

2222
- name: Run system tests
23-
command: bats --timing ./test/system
23+
command: meson test --suite system
2424
environment:
2525
PODMAN: '/usr/bin/podman'
2626
TOOLBOX: '/usr/local/bin/toolbox'
2727
args:
28-
chdir: '{{ zuul.project.src_dir }}'
28+
chdir: '{{ zuul.project.src_dir }}/builddir'

test/system/README.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,19 @@ by running `git submodule init` and `git submodule update`.
2929

3030
First, make sure you have all the dependencies installed.
3131

32-
- Enter the toolbox root folder
33-
- Invoke command `bats ./test/system/` and the test suite should fire up
32+
### Meson (recommended)
33+
34+
> This method is optimal when bulding from source
35+
36+
- Set up the project per instructions at https://containertoolbx.org/install
37+
- Invoke command `meson test --suite system` and the test suite should fire up
38+
39+
### Manually (legacy)
40+
41+
> This method is optimal if you want to test an existing build of Toolbx
42+
43+
- Enter the `test/system` directory in the project root directory
44+
- Invoke command `bats ./` and the test suite should fire up
3445

3546
Mocking of images is done automatically to prevent potential networking issues
3647
and to speed up the cases.
@@ -41,7 +52,7 @@ By default the test suite uses the system versions of `podman`, `skopeo` and
4152
If you have a `podman`, `skopeo` or `toolbox` installed in a nonstandard
4253
location then you can use the `PODMAN`, `SKOPEO` and `TOOLBOX` environmental
4354
variables to set the path to the binaries. So the command to invoke the test
44-
suite could look something like this: `PODMAN=/usr/libexec/podman TOOLBOX=./toolbox bats ./test/system/`.
55+
suite could look something like this: `PODMAN=/usr/libexec/podman TOOLBOX=./toolbox bats ./`.
4556

4657
When running the tests, make sure the `test suite: [job]` jobs are successful.
4758
These jobs set up the whole environment and are a strict requirement for other

test/system/libs/meson.build

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
test_system_libs_dir = test_system_dir / 'libs'
2+
3+
test_system_libs_files = files(
4+
'helpers.bash'
5+
)
6+
7+
install_data(
8+
install_dir: test_system_libs_dir,
9+
sources: test_system_libs_files
10+
)
11+
12+
install_subdir(
13+
'bats-support',
14+
install_dir: test_system_libs_dir,
15+
exclude_files: [
16+
'.git',
17+
'.gitignore',
18+
'.travis.yml',
19+
'package.json'
20+
],
21+
exclude_directories: [
22+
'.git',
23+
'script',
24+
'test'
25+
]
26+
)
27+
28+
install_subdir(
29+
'bats-assert',
30+
install_dir: test_system_libs_dir,
31+
exclude_files: [
32+
'.git',
33+
'.gitignore',
34+
'.travis.yml',
35+
'package.json'
36+
],
37+
exclude_directories: [
38+
'.git',
39+
'script',
40+
'test'
41+
]
42+
)

test/system/meson.build

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
test_system_dir = get_option('datadir') / meson.project_name() / 'test'
2+
3+
awk = find_program('awk', required: false)
4+
bats = find_program('bats', required: false)
5+
htpasswd = find_program('htpasswd', required: false)
6+
openssl = find_program('openssl', required: false)
7+
podman = find_program('podman', required: false)
8+
skopeo = find_program('skopeo', required: false)
9+
110
test_system = files(
211
'001-version.bats',
312
'002-help.bats',
@@ -15,9 +24,41 @@ test_system = files(
1524
'210-ulimit.bats',
1625
'211-dbus.bats',
1726
'setup_suite.bash',
18-
'libs/helpers.bash',
1927
)
2028

2129
if shellcheck.found()
2230
test('shellcheck test/system', shellcheck, args: [test_system])
2331
endif
32+
33+
if fs.exists('/run/.containerenv')
34+
warning('System tests can not be run in a container.')
35+
elif not awk.found() or not bats.found() or not htpasswd.found() or not openssl.found() or not podman.found() or not skopeo.found()
36+
warning('System tests require: awk, bats, htpasswd, openssl, podman and skopeo being installed.')
37+
else
38+
system_tests_env = environment()
39+
system_tests_env.set('TOOLBOX', toolbox_go.full_path())
40+
41+
test(
42+
'system tests',
43+
bats,
44+
args: [
45+
'--formatter', 'tap',
46+
'--timing',
47+
'./'],
48+
depends: toolbox_go,
49+
env: system_tests_env,
50+
is_parallel: false,
51+
protocol: 'tap',
52+
suite: 'system',
53+
timeout: 3600,
54+
verbose: true,
55+
workdir: meson.current_source_dir(),
56+
)
57+
endif
58+
59+
install_data(
60+
install_dir: test_system_dir,
61+
sources: [test_system, 'README.md'],
62+
)
63+
64+
subdir('libs')

test/system/setup_suite.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
missing_dependencies=false
1919

20-
if [ -f test/system/libs/bats-assert/load.bash ] && [ -f test/system/libs/bats-support/load.bash ]; then
20+
if [ -f libs/bats-assert/load.bash ] && [ -f libs/bats-support/load.bash ]; then
2121
load 'libs/helpers'
2222
else
2323
missing_dependencies=true

0 commit comments

Comments
 (0)