From 0d43d22b5b810fa2c049f6d0951e676ccdc35264 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Mon, 25 Sep 2023 15:52:19 +0200 Subject: [PATCH 1/4] test/system: Simplify checking if the image exists or not Bats' 'run' helper is not necessary to merely check if a command succeeded or not [1]. In this case, it's idiomatic to use the command as the condition for an 'if' branch. [1] https://bats-core.readthedocs.io/en/stable/writing-tests.html https://github.com/containers/toolbox/pull/1378 --- test/system/libs/helpers.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash index f4132d058..f32307954 100644 --- a/test/system/libs/helpers.bash +++ b/test/system/libs/helpers.bash @@ -334,8 +334,7 @@ function pull_distro_image() { fi # No need to copy if the image is already available in Podman - run "$PODMAN" image exists "${image}" - if [[ "$status" -eq 0 ]]; then + if "$PODMAN" image exists "${image}"; then return fi From 574dbc920c194225c4ba676faf947710f9c35d79 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Mon, 25 Sep 2023 15:56:49 +0200 Subject: [PATCH 2/4] test/system: Specify explit return values This removes any ambiguities and makes it clear what value is being returned. https://github.com/containers/toolbox/pull/1378 --- test/system/libs/helpers.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash index f32307954..833303ac6 100644 --- a/test/system/libs/helpers.bash +++ b/test/system/libs/helpers.bash @@ -335,7 +335,7 @@ function pull_distro_image() { # No need to copy if the image is already available in Podman if "$PODMAN" image exists "${image}"; then - return + return 0 fi # https://github.com/containers/skopeo/issues/547 for the options for containers-storage @@ -344,6 +344,8 @@ function pull_distro_image() { echo "Failed to load image ${image} from cache ${IMAGE_CACHE_DIR}/${image_archive}" assert_success fi + + return 0 } From 4362c39c134991a52eff8267587e7889a81043d2 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Mon, 25 Sep 2023 18:01:44 +0200 Subject: [PATCH 3/4] test/system: Silence SC2154 Otherwise https://www.shellcheck.net/ would complain: Line 343: if [ "$status" -ne 0 ]; then ^-----^ SC2154 (warning): status is referenced but not assigned. See: https://www.shellcheck.net/wiki/SC2154 https://github.com/containers/toolbox/pull/1378 --- test/system/libs/helpers.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash index 833303ac6..248ba4df7 100644 --- a/test/system/libs/helpers.bash +++ b/test/system/libs/helpers.bash @@ -340,6 +340,8 @@ function pull_distro_image() { # https://github.com/containers/skopeo/issues/547 for the options for containers-storage run "$SKOPEO" copy "dir:${IMAGE_CACHE_DIR}/${image_archive}" "containers-storage:[overlay@$ROOTLESS_PODMAN_STORE_DIR+$ROOTLESS_PODMAN_STORE_DIR]${image}" + + # shellcheck disable=SC2154 if [ "$status" -ne 0 ]; then echo "Failed to load image ${image} from cache ${IMAGE_CACHE_DIR}/${image_archive}" assert_success From 4ebaea6803735969fe9aa06799932de906db2eb4 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Tue, 4 Jul 2023 16:07:46 +0200 Subject: [PATCH 4/4] build: Enforce shellcheck(1) on all Bats tests https://github.com/containers/toolbox/pull/1331 --- test/system/meson.build | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/system/meson.build b/test/system/meson.build index fface8222..9546ef7fb 100644 --- a/test/system/meson.build +++ b/test/system/meson.build @@ -1,9 +1,21 @@ test_system = files( + '001-version.bats', + '002-help.bats', + '101-create.bats', + '102-list.bats', + '103-container.bats', + '104-run.bats', + '105-enter.bats', + '106-rm.bats', + '107-rmi.bats', + '108-completion.bats', '201-ipc.bats', '203-network.bats', '206-user.bats', '210-ulimit.bats', '211-dbus.bats', + 'setup_suite.bash', + 'libs/helpers.bash', ) if shellcheck.found()