toolbox/test/system/102-list.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

83 lines
1.9 KiB
Bash

#!/usr/bin/env bats
load 'libs/bats-support/load'
load 'libs/bats-assert/load'
load 'libs/helpers'
setup() {
cleanup_all
}
teardown() {
cleanup_all
}
@test "list: Run 'list' with zero containers and zero images (the list should be empty)" {
run toolbox list
assert_success
assert_output ""
}
@test "list: Run 'list -c' with zero containers (the list should be empty)" {
run toolbox list -c
assert_success
assert_output ""
}
@test "list: Run 'list -i' with zero images (the list should be empty)" {
run toolbox list -c
assert_success
assert_output ""
}
@test "list: Run 'list' with zero toolbox's containers and images, but other image (the list should be empty)" {
get_busybox_image
run podman images
assert_output --partial "$BUSYBOX_IMAGE"
run toolbox list
assert_success
assert_output ""
}
@test "list: Try to list images and containers (no flag) with 3 containers and 2 images (the list should have 3 images and 2 containers)" {
# Pull the two images
pull_default_image
pull_image 29
# Create tree containers
create_default_container
create_container non-default-one
create_container non-default-two
# Check images
run toolbox list --images
assert_success
assert_output --partial "fedora-toolbox:${DEFAULT_FEDORA_VERSION}"
assert_output --partial "fedora-toolbox:29"
# Check containers
run toolbox list --containers
assert_success
assert_output --partial "fedora-toolbox-${DEFAULT_FEDORA_VERSION}"
assert_output --partial "non-default-one"
assert_output --partial "non-default-two"
# Check all together
run toolbox list
assert_success
assert_output --partial "fedora-toolbox:${DEFAULT_FEDORA_VERSION}"
assert_output --partial "fedora-toolbox:29"
assert_output --partial "fedora-toolbox-${DEFAULT_FEDORA_VERSION}"
assert_output --partial "non-default-one"
assert_output --partial "non-default-two"
}