From a0d4c957b34ef6b5569123522a4bd693a6ddee44 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 9 Dec 2022 11:02:28 +0100 Subject: [PATCH] test/system: Test 'rmi' with an image without a name https://github.com/containers/toolbox/pull/1195 --- test/system/102-list.bats | 4 ++-- test/system/107-rmi.bats | 27 ++++++++++++++++++++++++++- test/system/libs/helpers.bash | 4 ++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/test/system/102-list.bats b/test/system/102-list.bats index 9e48cce..b0ce095 100644 --- a/test/system/102-list.bats +++ b/test/system/102-list.bats @@ -64,7 +64,7 @@ teardown() { } @test "list: List an image without a name" { - build_image_without_name + build_image_without_name >/dev/null run --keep-empty-lines --separate-stderr $TOOLBOX list @@ -130,7 +130,7 @@ teardown() { pull_default_image pull_distro_image fedora 34 - build_image_without_name + build_image_without_name >/dev/null run --keep-empty-lines --separate-stderr "$TOOLBOX" list --images diff --git a/test/system/107-rmi.bats b/test/system/107-rmi.bats index 0f62e9e..7e9a2f0 100644 --- a/test/system/107-rmi.bats +++ b/test/system/107-rmi.bats @@ -70,7 +70,7 @@ teardown() { num_of_images="$(list_images)" assert_equal "$num_of_images" 0 - build_image_without_name + build_image_without_name >/dev/null num_of_images="$(list_images)" assert_equal "$num_of_images" 1 @@ -90,6 +90,31 @@ teardown() { assert_equal "$num_of_images" 0 } +@test "rmi: An image without a name" { + local num_of_images + num_of_images="$(list_images)" + assert_equal "$num_of_images" 0 + + image="$(build_image_without_name)" + + num_of_images="$(list_images)" + assert_equal "$num_of_images" 1 + + run --keep-empty-lines --separate-stderr "$TOOLBOX" rmi "$image" + + assert_success + assert_output "" + output="$stderr" + assert_output "" + if check_bats_version 1.7.0; then + assert [ ${#lines[@]} -eq 0 ] + assert [ ${#stderr_lines[@]} -eq 0 ] + fi + + num_of_images="$(list_images)" + assert_equal "$num_of_images" 0 +} + @test "rmi: Try to remove all images with a container present and running" { skip "Bug: Fail in 'toolbox rmi' does not return non-zero value" num_of_images=$(list_images) diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash index b9bf256..7d18737 100644 --- a/test/system/libs/helpers.bash +++ b/test/system/libs/helpers.bash @@ -234,8 +234,12 @@ function build_image_without_name() { assert_line --index 1 --partial "LABEL com.github.containers.toolbox=\"true\"" assert_line --index 2 --partial "COMMIT" assert_line --index 3 --regexp "^--> [a-z0-9]*$" + last=$((${#lines[@]}-1)) + assert_line --index "$last" --regexp "^[a-f0-9]{64}$" rm -f "$BATS_TMPDIR"/Containerfile + + echo "${lines[$last]}" }