toolbox/test/system/102-list.bats
Ondřej Míchal e09de9f3e5 list: Recognize UBI8 as Toolbox image & split tracked labels
UBI[0] does not have the recommend Toolbox labels used to track whether
an image/container is truly a toolbox image/container. Thankfully, they
have a number of labels to choose from that we can use to identify the
image. The "com.redhat.component=ubi8-container" seems to be ideal.

The approach of using the UBI8 label introduces one problem though. If
we were to use only one set of labels for both images and containers,
containers created with Podman and not Toolbox from UBI8 would also be
marked as toolbox containers. This is not desired and therefore there
are now two sets of labels. Ones for images where the new label has been
added and other for containers that stays the same.
2021-06-01 01:49:54 +02:00

112 lines
2.7 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)" {
pull_distro_image busybox
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_distro_image fedora 32
# Create three 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 "$(get_system_id)-toolbox:$(get_system_version)"
assert_output --partial "fedora-toolbox:32"
# Check containers
run $TOOLBOX list --containers
assert_success
assert_output --partial "$(get_system_id)-toolbox-$(get_system_version)"
assert_output --partial "non-default-one"
assert_output --partial "non-default-two"
# Check all together
run $TOOLBOX list
assert_success
assert_output --partial "$(get_system_id)-toolbox:$(get_system_version)"
assert_output --partial "fedora-toolbox:32"
assert_output --partial "$(get_system_id)-toolbox-$(get_system_version)"
assert_output --partial "non-default-one"
assert_output --partial "non-default-two"
}
@test "list: Run 'list -i' with UBI image (8.4; public) present" {
pull_distro_image rhel 8.4
run toolbox list --images
assert_success
assert_output --partial "registry.access.redhat.com/ubi8/ubi:8.4"
}
@test "list: Run 'list' with UBI image (8.4; public), toolbox container and non-toolbox container" {
local num_of_containers
pull_distro_image rhel 8.4
create_distro_container rhel 8.4 rhel-toolbox
podman create --name podman-container ubi8/ubi:8.4 /bin/sh
num_of_containers=$(list_containers)
assert [ $num_of_containers -eq 2 ]
run toolbox list
assert_success
assert_line --index 1 --partial "registry.access.redhat.com/ubi8/ubi:8.4"
assert_line --index 3 --partial "rhel-toolbox"
refute_output --partial "podman-container"
}