Skip to content

Commit

Permalink
Add system test scripts
Browse files Browse the repository at this point in the history
These tests are written using BATS (Bash Automated Testing System). I
used a very helpful helpers.bash script from the libpod project (Thank
you!) that I tweaked slightly.

#68
  • Loading branch information
HarryMichal authored and debarshiray committed Jan 22, 2020
1 parent 7b460e3 commit b5cdc57
Show file tree
Hide file tree
Showing 6 changed files with 478 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/system/001-basics.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bats

load helpers

function setup() {
:
}

function teardown() {
:
}

@test "Output version number using full flag" {
skip "Not implemented"
run_toolbox --version
}

@test "Output version number using command" {
skip "Not implemented"
run_toolbox version
}

@test "Show usage screen when no command is given" {
run_toolbox 1
is "${lines[0]}" "toolbox: missing command" "Usage line 1"
}
20 changes: 20 additions & 0 deletions test/system/101-create.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bats

load helpers

@test "Create the default container." {
run_toolbox -y create
}

@test "Create a container with a valid custom name (whole word)" {
run_toolbox -y create -c "customname"
}

@test "Try to create a container with a bad custom name (with special characters)" {
run_toolbox 1 -y create -c "ß[email protected]"
is "${lines[0]}" "toolbox: invalid argument for '--container'" "Toolbox reports invalid argument for --container"
}

@test "Create a container with a custom image (f29)" {
run_toolbox -y create -i fedora-toolbox:29
}
44 changes: 44 additions & 0 deletions test/system/102-list.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bats

load helpers

@test "Run list with zero containers and zero images" {
remove_all_images
remove_all_containers
run_toolbox list
is "$output" "" "Output of list should be blank"
}

@test "Run list with zero containers (-c flag)" {
remove_all_containers
run_toolbox list -c
is "$output" "" "Output of list should be blank"
}

@test "Run list with zero images (-i flag)" {
remove_all_images
run_toolbox list -i
is "$output" "" "Output of list should be blank"
}

@test "Run list with 1 default container and 1 default image" {
create_toolbox
run_toolbox list
is "${lines[1]}" ".*registry.fedoraproject.org/.*" "Default image"
is "${lines[3]}" ".*fedora-toolbox-.*" "Default container"
is "${#lines[@]}" "4" "Expected length of output is 4"
}

@test "Run list with 3 containers (-c flag)" {
create_toolbox 3 fedora
run_toolbox list -c
for i in $(seq 1 3); do
is "${lines[$i]}" ".*fedora-$((i)) \+" "One of the containers"
done
}

@test "Run list with 3 images (-i flag)" {
get_images 3
run_toolbox list -i
is "${#lines[@]}" "4" "Expected length of output is 4"
}
56 changes: 56 additions & 0 deletions test/system/103-remove.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bats

load helpers

@test "Remove a specific container (called fedora-2)" {
create_toolbox 2 fedora
run_toolbox rm fedora-2
is "$output" "" "Successfull removal shouldn't print anything"
}

@test "Remove a specific image (default image called by name)" {
get_images 1
run_toolbox rmi "$TOOLBOX_DEFAULT_IMAGE"
}

@test "Try to remove a nonexistent container" {
local todelete="nonexistentcontainer"
run_toolbox 1 rm "$todelete"
is "$output" "toolbox: failed to inspect $todelete" "Toolbox should fail with: no such container"
}

@test "Try to remove a nonexistent image" {
local todelete="nonexistentimage"
run_toolbox 1 rmi "$todelete"
}

@test "Try to remove a running container (called fedora-1)" {
create_toolbox 1 fedora
run_toolbox run -c fedora-1 echo "WAKE UP"
run_toolbox 1 rm fedora-1
is "$output" "toolbox: failed to remove container fedora-1" "Toolbox should fail to remove the container"
}

@test "Remove all containers (2 present)" {
create_toolbox 2 fedora
run_toolbox rm --all
is "$output" "" ""
}

@test "Remove all images" {
get_images 2
run_toolbox rmi --all
}

@test "Try to remove all containers (running containers)" {
create_toolbox 2 fedora
run_toolbox run -c fedora-1 echo "WAKE UP"
run_toolbox run -c fedora-2 echo "WAKE UP"
run_toolbox 1 rm --all
}

@test "Try to remove all images with present containers" {
get_images 2
create_toolbox 2 fedora
run_toolbox 1 rmi --all
}
12 changes: 12 additions & 0 deletions test/system/104-run.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bats

load helpers

function setup() {
setup_with_one_container
}

@test "Echo 'Hello World' inside of an container" {
run_toolbox run echo "Hello World"
is "$output" "Hello World" "Should say 'Hello World'"
}
Loading

0 comments on commit b5cdc57

Please sign in to comment.