Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/system: Miscellaneous improvements to the 'list' tests (2) #1273

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/system/000-setup.bats
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bats
#
# Copyright © 2021 – 2022 Red Hat, Inc.
# Copyright © 2021 – 2023 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -27,6 +27,7 @@ load 'libs/helpers'
_pull_and_cache_distro_image "$system_id" "$system_version" || false
# Cache all images that will be needed during the tests
_pull_and_cache_distro_image fedora 34 || false
_pull_and_cache_distro_image rhel 8.7 || false
_pull_and_cache_distro_image busybox || false
# If run on Fedora Rawhide, cache 2 extra images (previous Fedora versions)
local rawhide_res="$(awk '/rawhide/' $os_release)"
Expand Down
129 changes: 121 additions & 8 deletions test/system/102-list.bats
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,43 @@ teardown() {
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "list: RHEL 8.7 image" {
pull_distro_image rhel 8.7

local num_of_images
num_of_images="$(list_images)"
assert_equal "$num_of_images" 1

run --keep-empty-lines --separate-stderr "$TOOLBOX" list

assert_success
assert_line --index 1 --partial "registry.access.redhat.com/ubi8/toolbox:8.7"
assert [ ${#lines[@]} -eq 3 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "list: RHEL 8.7 image (using --images)" {
pull_distro_image rhel 8.7

local num_of_images
num_of_images="$(list_images)"
assert_equal "$num_of_images" 1

run --keep-empty-lines --separate-stderr "$TOOLBOX" list --images

assert_success
assert_line --index 1 --partial "registry.access.redhat.com/ubi8/toolbox:8.7"
assert [ ${#lines[@]} -eq 3 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "list: An image without a name" {
build_image_without_name >/dev/null

local num_of_images
num_of_images="$(list_images)"
assert_equal "$num_of_images" 1

run --keep-empty-lines --separate-stderr $TOOLBOX list

assert_success
Expand Down Expand Up @@ -213,10 +247,20 @@ teardown() {
}

@test "list: Containers and images" {
local default_image
default_image="$(get_default_image)"

local default_container
default_container="$(get_system_id)-toolbox-$(get_system_version)"

# Pull the two images
pull_default_image
pull_distro_image fedora 34

local num_of_images
num_of_images="$(list_images)"
assert_equal "$num_of_images" 2

# Create three containers
create_default_container
create_container non-default-one
Expand All @@ -226,16 +270,16 @@ teardown() {
run --keep-empty-lines --separate-stderr $TOOLBOX list --images

assert_success
assert_line --index 1 --partial "fedora-toolbox:34"
assert_line --index 2 --partial "$(get_system_id)-toolbox:$(get_system_version)"
assert_line --index 1 --partial "registry.fedoraproject.org/fedora-toolbox:34"
assert_line --index 2 --partial "$default_image"
assert [ ${#lines[@]} -eq 4 ]
assert [ ${#stderr_lines[@]} -eq 0 ]

# Check containers
run --keep-empty-lines --separate-stderr $TOOLBOX list --containers

assert_success
assert_line --index 1 --partial "$(get_system_id)-toolbox-$(get_system_version)"
assert_line --index 1 --partial "$default_container"
assert_line --index 2 --partial "non-default-one"
assert_line --index 3 --partial "non-default-two"
assert [ ${#lines[@]} -eq 5 ]
Expand All @@ -245,9 +289,9 @@ teardown() {
run --keep-empty-lines --separate-stderr $TOOLBOX list

assert_success
assert_line --index 1 --partial "fedora-toolbox:34"
assert_line --index 2 --partial "$(get_system_id)-toolbox:$(get_system_version)"
assert_line --index 5 --partial "$(get_system_id)-toolbox-$(get_system_version)"
assert_line --index 1 --partial "registry.fedoraproject.org/fedora-toolbox:34"
assert_line --index 2 --partial "$default_image"
assert_line --index 5 --partial "$default_container"
assert_line --index 6 --partial "non-default-one"
assert_line --index 7 --partial "non-default-two"
assert [ ${#lines[@]} -eq 9 ]
Expand All @@ -270,7 +314,7 @@ teardown() {

assert_success
assert_line --index 1 --partial "<none>"
assert_line --index 2 --partial "fedora-toolbox:34"
assert_line --index 2 --partial "registry.fedoraproject.org/fedora-toolbox:34"
assert_line --index 3 --partial "$default_image"
assert [ ${#lines[@]} -eq 5 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
Expand All @@ -288,8 +332,77 @@ teardown() {

assert_success
assert_line --index 1 --partial "<none>"
assert_line --index 2 --partial "fedora-toolbox:34"
assert_line --index 2 --partial "registry.fedoraproject.org/fedora-toolbox:34"
assert_line --index 3 --partial "$default_image"
assert [ ${#lines[@]} -eq 5 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "list: With just one non-Toolbx container and one non-Toolbx image" {
local busybox_image
busybox_image="$(get_busybox_image)"

pull_distro_image busybox

local num_of_images
num_of_images="$(list_images)"
assert_equal "$num_of_images" 1

$PODMAN create --name busybox-container "$busybox_image"

local num_of_containers
num_of_containers="$(list_containers)"
assert_equal "$num_of_containers" 1

run --keep-empty-lines --separate-stderr $TOOLBOX list

assert_success
assert [ ${#lines[@]} -eq 0 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "list: With just one non-Toolbx container and one non-Toolbx image (using --containers)" {
local busybox_image
busybox_image="$(get_busybox_image)"

pull_distro_image busybox

local num_of_images
num_of_images="$(list_images)"
assert_equal "$num_of_images" 1

$PODMAN create --name busybox-container "$busybox_image"

local num_of_containers
num_of_containers="$(list_containers)"
assert_equal "$num_of_containers" 1

run --keep-empty-lines --separate-stderr $TOOLBOX list --containers

assert_success
assert [ ${#lines[@]} -eq 0 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "list: With just one non-Toolbx container and one non-Toolbx image (using --images)" {
local busybox_image
busybox_image="$(get_busybox_image)"

pull_distro_image busybox

local num_of_images
num_of_images="$(list_images)"
assert_equal "$num_of_images" 1

$PODMAN create --name busybox-container "$busybox_image"

local num_of_containers
num_of_containers="$(list_containers)"
assert_equal "$num_of_containers" 1

run --keep-empty-lines --separate-stderr $TOOLBOX list --images

assert_success
assert [ ${#lines[@]} -eq 0 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
}
8 changes: 8 additions & 0 deletions test/system/libs/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ function check_bats_version() {
}


function get_busybox_image() {
local image
image="${IMAGES[busybox]}"
echo "$image"
return 0
}


function get_default_image() {
local distro
local image
Expand Down