diff --git a/test/system/102-list.bats b/test/system/102-list.bats index 3a98778..de7b067 100644 --- a/test/system/102-list.bats +++ b/test/system/102-list.bats @@ -107,3 +107,23 @@ teardown() { assert_line --index 6 --partial "non-default-one" assert_line --index 7 --partial "non-default-two" } + +@test "list: Images with and without names" { + local default_image + default_image="$(get_default_image)" + + pull_default_image + pull_distro_image fedora 34 + build_image_without_name + + run --keep-empty-lines --separate-stderr "$TOOLBOX" list --images + + assert_success + assert_line --index 1 --partial "" + assert_line --index 2 --partial "$default_image" + assert_line --index 3 --partial "fedora-toolbox:34" + assert [ ${#lines[@]} -eq 5 ] + if check_bats_version 1.7.0; then + assert [ ${#stderr_lines[@]} -eq 0 ] + fi +} diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash index f223cee..47dd40c 100644 --- a/test/system/libs/helpers.bash +++ b/test/system/libs/helpers.bash @@ -239,6 +239,36 @@ function build_image_without_name() { } +function check_bats_version() { + local required_version + required_version="$1" + + if ! old_version=$(printf "%s\n%s\n" "$BATS_VERSION" "$required_version" | sort --version-sort | head --lines 1); then + return 1 + fi + + if [ "$required_version" = "$old_version" ]; then + return 0 + fi + + return 1 +} + + +function get_default_image() { + local distro + local image + local release + + distro="$(get_system_id)" + release="$(get_system_version)" + image="${IMAGES[$distro]}:$release" + + echo "$image" + return 0 +} + + # Copies an image from local storage to Podman's image store # # Call before creating any container. Network failures are not nice.