Skip to content

Commit 1e22327

Browse files
martymichaldebarshiray
authored andcommitted
test/system: Rework the tests
The tests introduced by commit b5cdc57 have proven to be rather unstable due to mistakes in their design. The tests were quite chaotically structured, and because of that images were deleted and pulled too often, causing several false positives [1, 2]. This changes the structure of the tests in a major way. The tests (resp. commands) are now run in a manner that better simulates the way Toolbox is actually used. From a clean state, through creating containers, using them and in the end deleting them. This should reduce the strain on the bandwidth and possibly even speed up the tests themselves. [1] containers#372 [2] containers#374 containers#375
1 parent 50683c9 commit 1e22327

14 files changed

+148
-208
lines changed

test/system/001-basics.bats renamed to test/system/001-version.bats

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
load helpers
44

5-
function setup() {
6-
:
7-
}
8-
9-
function teardown() {
10-
:
11-
}
12-
135
@test "Output version number using full flag" {
146
skip "Not implemented"
157
run_toolbox --version
@@ -20,7 +12,3 @@ function teardown() {
2012
run_toolbox version
2113
}
2214

23-
@test "Show usage screen when no command is given" {
24-
run_toolbox 1
25-
is "${lines[0]}" "toolbox: missing command" "Usage line 1"
26-
}

test/system/002-help.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
@test "Show usage screen when no command is given" {
6+
run_toolbox 1
7+
is "${lines[0]}" "toolbox: missing command" "Usage line 1"
8+
}

test/system/101-create.bats

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/system/101-list.bats

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
@test "Run list with zero containers and two images" {
6+
run_toolbox list
7+
is "${#lines[@]}" "3" "Expected number of lines of the output is 3 (Img: 3 + Spc: 0 + Cont: 0)"
8+
9+
is "${lines[1]}" ".*registry.fedoraproject.org/.*" "First of the two images"
10+
is "${lines[2]}" ".*registry.fedoraproject.org/.*" "Second of the two images"
11+
}
12+
13+
@test "Run list with zero containers (-c flag)" {
14+
run_toolbox list -c
15+
is "$output" "" "Output of list should be blank"
16+
}
17+
18+
@test "Run list with zero images (-i flag)" {
19+
run_toolbox list -i
20+
is "${#lines[@]}" "3" "Expected number of lines of the output is 3"
21+
22+
is "${lines[1]}" ".*registry.fedoraproject.org/.*" "First of the two images"
23+
is "${lines[2]}" ".*registry.fedoraproject.org/.*" "Second of the two images"
24+
}

test/system/102-create.bats

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
@test "Create the default container" {
6+
run_toolbox -y create
7+
}
8+
9+
@test "Create a container with a valid custom name ('not-running')" {
10+
run_toolbox -y create -c "not-running"
11+
}
12+
13+
@test "Create a container with a custom image and name ('running';f29)" {
14+
run_toolbox -y create -c "running" -i fedora-toolbox:29
15+
}
16+
17+
@test "Try to create a container with invalid custom name" {
18+
run_toolbox 1 -y create -c "ß[email protected]"
19+
is "${lines[0]}" "toolbox: invalid argument for '--container'" "Toolbox reports invalid argument for --container"
20+
}

test/system/102-list.bats

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/system/103-list.bats

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
@test "Run list with three containers and two images" {
6+
run_toolbox list
7+
is "${#lines[@]}" "8" "Expected number of lines of the output is 8 (Img: 3 + Cont: 5 (duplication expected))"
8+
9+
is "${lines[1]}" ".*registry.fedoraproject.org/.*" "The first of the two images"
10+
is "${lines[2]}" ".*registry.fedoraproject.org/.*" "The second of the two images"
11+
12+
is "${lines[4]}" ".*fedora-toolbox-.*" "The default container should be first in the list"
13+
is "${lines[5]}" ".*not-running.*" "The container 'not-running' should be second"
14+
is "${lines[6]}" ".*running.*" "The container 'running' should be third (last)"
15+
}

test/system/103-remove.bats

Lines changed: 0 additions & 56 deletions
This file was deleted.

test/system/104-run.bats

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/system/201-run.bats

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
@test "Echo 'Hello World' inside of the default container" {
6+
run_toolbox run echo "Hello World"
7+
is "$output" "Hello World" "Should say 'Hello World'"
8+
}
9+
10+
@test "Echo 'Hello World' inside of the 'running' container" {
11+
run_toolbox run -c running echo "Hello World"
12+
is "$output" "Hello World" "Should say 'Hello World'"
13+
}
14+
15+
@test "Stop the 'running' container using 'podman stop'" {
16+
run_podman stop running
17+
is "${#lines[@]}" "1" "Expected number of lines of the output is 1 (with the id of the container)"
18+
}
19+
20+
@test "Echo 'hello World' again in the 'running' container after being stopped and exit" {
21+
run_toolbox run -c running echo "Hello World"
22+
is "$output" "Hello World" "Should say 'Hello World'"
23+
}

test/system/301-rm.bats

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
@test "Try to remove a nonexistent container" {
6+
run_toolbox 1 rm nonexistentcontainer
7+
is "$output" "toolbox: failed to inspect $todelete" "Toolbox should fail with: no such container"
8+
}
9+
10+
@test "Try to remove the running container 'running'" {
11+
run_toolbox 1 rm running
12+
is "$output" "toolbox: failed to remove container running" "Toolbox should fail to remove the running container"
13+
}
14+
15+
@test "Remove the not running container 'not-running'" {
16+
run_toolbox rm not-running
17+
is "$output" "" "The output should be empty"
18+
}
19+
20+
@test "Force remove the running container 'running'" {
21+
run_toolbox rm --force running
22+
is "$output" "" "The output should be empty"
23+
}
24+
25+
@test "Force remove all remaining containers (only 1 should be left)" {
26+
run_toolbox rm --force --all
27+
is "$output" "" "The output should be empty"
28+
}

test/system/302-rmi.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
@test "Remove all images (2 should be present; --force should not be necessary)" {
6+
run_toolbox rmi --all
7+
is "$output" "" "The output should be empty"
8+
}

test/system/README.md

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,23 @@ throughout updates of both Toolbox and Podman/libpod.
99

1010
## Structure
1111

12-
- **Basic Tests**
13-
- [] output version number (Toolbox + Podman)
14-
- [x] show help screen when no command is given
15-
- [x] create the default container
16-
- [x] create a container with a custom name
17-
- [x] create a container from a custom image
18-
- [x] list containers (no present)
19-
- [x] list default container and default image
20-
- [x] list containers (some present; different name patterns)
21-
- [x] list images (no present)
22-
- [x] list images (some present; different name patterns)
23-
- [x] remove a specific container
24-
- [x] try to remove nonexistent container
25-
- [x] try to remove a running container
26-
- [x] remove all containers
27-
- [x] try to remove all containers (running)
28-
- [x] remove a specific image
29-
- [x] remove all images
30-
- [x] run a command inside of an existing container
31-
32-
- **Advanced Tests**
33-
- [ ] create several containers with various configuration and then list them
34-
- [ ] create several containers and hop between them (series of enter/exit)
35-
- [ ] create a container, enter it, run a series of basic commands (id,
36-
whoami, dnf, top, systemctl,..)
37-
- [ ] enter a container and test basic set of networking tools (ping,
38-
traceroute,..)
39-
40-
The list of tests is stil rather basic. We **welcome** PRs with test
41-
suggestions or even their implementation.
12+
- **0xx (Info)**
13+
- Commands that are not dependent on the presence/number of containers or
14+
images. eg., version, help, etc..
15+
- **1xx (Initialization)**
16+
- Commands (list, create) when Toolbox has not really been used, yet.
17+
- It tries to list an empty list, creates several containers (default one
18+
and several with custom names and images).
19+
- **2xx (Usage)**
20+
- The created containers are used for the first time testing the
21+
initialization (CMD of the container).
22+
- Not all containers will be used because in the *Cleanup* phase we want to
23+
try removing containers in both running and not running states.
24+
- **3xx (Cleanup)**
25+
- In this section the containers and images from the previous *phases* are
26+
removed.
27+
- There is a difference between removing running and not running containers.
28+
We need to check the right behaviour.
4229

4330
## Convention
4431

@@ -48,6 +35,11 @@ suggestions or even their implementation.
4835

4936
Make sure you have `bats` and `podman` with `toolbox` installed on your system.
5037

38+
**Important**
39+
Before you start the tests, you need to have present two images: the default
40+
`fedora-toolbox` image for your version of Fedora and the `fedora-toolbox:29`
41+
image.
42+
5143
- Enter the toolbox root folder
5244
- Invoke command `bats ./test/system/` and the test suite should fire up
5345

test/system/helpers.bash

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,6 @@ LGC='\033[1;32m' # Light Green Color
1717
LBC='\033[1;34m' # Light Blue Color
1818
NC='\033[0m' # No Color
1919

20-
# Basic setup
21-
function basic_setup() {
22-
echo "# [basic_setup]" >&2
23-
# Make sure desired images are present
24-
if [ -z "$found_needed_image" ]; then
25-
run_podman pull "$TOOLBOX_DEFAULT_IMAGE"
26-
fi
27-
}
28-
29-
function setup_with_one_container() {
30-
echo "# [setup_with_one_container]" >&2
31-
# Clean up all images except for the default one
32-
remove_all_images_but_default
33-
# Create a new (default) container if no other are present
34-
run_toolbox -y create
35-
}
36-
37-
function basic_teardown() {
38-
echo "# [basic_teardown]" >&2
39-
# Clean up all containers
40-
remove_all_containers
41-
# Clean up all images except for the default one
42-
remove_all_images_but_default
43-
}
44-
45-
# Set the default setup function
46-
function setup() {
47-
basic_setup
48-
}
49-
50-
function teardown() {
51-
basic_teardown
52-
}
53-
5420

5521
################
5622
# run_podman # Invoke $PODMAN, with timeout, using BATS 'run'

0 commit comments

Comments
 (0)