toolbox/test/system/104-rm.bats
Juanje Ojeda b27795a03e test/system: Refactor tests using bats-support and bats-assert
The bats-support[0] and bats-assert[1] libraries extend the
capabilities of bats[2]. Mainly, bats-assert is very useful for clean
checking of values/outputs/return codes.

Apart from updating the cases to use the libraries, the test cases have
been restructured in a way that they don't depend on each other anymore.
This required major changes in the helpers.bats file.

Overall, the tests are cleaner to read and easier to extend due to the
test cases being independent.

Some slight changes were made to the test cases themselves. Should not
alter their final behaviour.

There will be a follow up commit that will take care of downloading of
the tested images locally and caching them using Skopeo to speedup the
tests and try to resolve network problems when pulling the images that
we experienced in the past.

[0] https://github.com/bats-core/bats-support
[1] https://github.com/bats-core/bats-assert
[2] https://github.com/bats-core/bats-core
2021-02-12 14:02:08 +01:00

70 lines
1.4 KiB
Bash

#!/usr/bin/env bats
load 'libs/bats-support/load'
load 'libs/bats-assert/load'
load 'libs/helpers'
setup() {
cleanup_containers
}
teardown() {
cleanup_containers
}
@test "rm: Try to remove a non-existent container" {
container_name="nonexistentcontainer"
run toolbox rm "$container_name"
#assert_failure #BUG: it should return 1
assert_output "Error: failed to inspect container $container_name"
}
@test "rm: Try to remove a running container" {
skip "Bug: Fail in 'toolbox rm' does not return non-zero value"
create_container running
start_container running
run toolbox rm running
#assert_failure #BUG: it should return 1
assert_output "Error: container running is running"
}
@test "rm: Remove a not running container" {
create_container not-running
run toolbox rm not-running
assert_success
assert_output ""
}
@test "rm: Force remove a running container" {
create_container running
start_container running
run toolbox rm --force running
assert_success
assert_output ""
}
@test "rm: Force remove all containers (with 2 containers created and 1 running)" {
num_of_containers=$(list_containers)
assert_equal "$num_of_containers" 0
create_container running
create_container not-running
start_container running
run toolbox rm --force --all
assert_success
assert_output ""
new_num_of_containers=$(list_containers)
assert_equal "$new_num_of_containers" "$num_of_containers"
}