From c37c5238dd2613463a86cfd7818592ac66b55caf Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 21 Jun 2023 08:08:34 +0200 Subject: [PATCH 1/2] test/system: Re-align All the other Bats files for the system tests are indented by two spaces, not four. This will make the subsequent commit easier to read. https://github.com/containers/toolbox/pull/1317 --- test/system/000-setup.bats | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/test/system/000-setup.bats b/test/system/000-setup.bats index 4460a0823..e1bfdeb6e 100644 --- a/test/system/000-setup.bats +++ b/test/system/000-setup.bats @@ -18,27 +18,27 @@ load 'libs/helpers' @test "test suite: Set up" { - local os_release="$(find_os_release)" - local system_id="$(get_system_id)" - local system_version="$(get_system_version)" + local os_release="$(find_os_release)" + local system_id="$(get_system_id)" + local system_version="$(get_system_version)" - _setup_environment - # Cache the default image for the system - _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 arch latest || false - _pull_and_cache_distro_image fedora 34 || false - _pull_and_cache_distro_image rhel 8.7 || false - _pull_and_cache_distro_image ubuntu 16.04 || false - _pull_and_cache_distro_image ubuntu 18.04 || false - _pull_and_cache_distro_image ubuntu 20.04 || 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)" - if [ "$system_id" = "fedora" ] && [ -n "$rawhide_res" ]; then - _pull_and_cache_distro_image fedora "$((system_version-1))" || false - _pull_and_cache_distro_image fedora "$((system_version-2))" || false - fi + _setup_environment + # Cache the default image for the system + _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 arch latest || false + _pull_and_cache_distro_image fedora 34 || false + _pull_and_cache_distro_image rhel 8.7 || false + _pull_and_cache_distro_image ubuntu 16.04 || false + _pull_and_cache_distro_image ubuntu 18.04 || false + _pull_and_cache_distro_image ubuntu 20.04 || 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)" + if [ "$system_id" = "fedora" ] && [ -n "$rawhide_res" ]; then + _pull_and_cache_distro_image fedora "$((system_version-1))" || false + _pull_and_cache_distro_image fedora "$((system_version-2))" || false + fi - _setup_docker_registry + _setup_docker_registry } From 7a387dcc8b098504d5647378d800f95ae376efb2 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 21 Jun 2023 08:04:28 +0200 Subject: [PATCH 2/2] test/system: Simplify running a subset of the tests with Bats >= 1.7.0 The 000-setup.bats and 999-teardown.bats files were added [1] at a time when Bats didn't offer any hooks for suite-wide setup and teardown. That changed in Bats 1.7.0, which introduced the setup_suite and teardown_suite hooks. These hooks make it easier to run a subset of the tests, which is a good thing. In the past, to run a subset of the tests, one had to do: $ bats ./test/system/000-setup.bats ./test/system/002-help.bats \ ./test/system/999-teardown.bats Now, one only has to do: $ bats ./test/system/002-help.bats Commit e22a82fec8e59c5a already added a dependency on Bats >= 1.7.0. Therefore, it should be exploited wherever possible to simplify things. [1] Commit 54a2ca1ead343c3d https://github.com/containers/toolbox/issues/751 [2] Bats commit fb467ec3f04e322a https://github.com/bats-core/bats-core/issues/39 https://bats-core.readthedocs.io/en/stable/writing-tests.html https://github.com/containers/toolbox/pull/1317 --- test/system/999-teardown.bats | 26 ------------------- .../{000-setup.bats => setup_suite.bash} | 16 +++++++++++- 2 files changed, 15 insertions(+), 27 deletions(-) delete mode 100644 test/system/999-teardown.bats rename test/system/{000-setup.bats => setup_suite.bash} (85%) diff --git a/test/system/999-teardown.bats b/test/system/999-teardown.bats deleted file mode 100644 index 30e96e704..000000000 --- a/test/system/999-teardown.bats +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bats -# -# Copyright © 2021 – 2022 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. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -load 'libs/helpers' - -@test "test suite: Teardown" { - _setup_environment - - _clean_cached_images - _clean_docker_registry - _clean_temporary_storage -} diff --git a/test/system/000-setup.bats b/test/system/setup_suite.bash similarity index 85% rename from test/system/000-setup.bats rename to test/system/setup_suite.bash index e1bfdeb6e..a3956a618 100644 --- a/test/system/000-setup.bats +++ b/test/system/setup_suite.bash @@ -17,7 +17,10 @@ load 'libs/helpers' -@test "test suite: Set up" { +setup_suite() { + bats_require_minimum_version 1.7.0 + echo "# test suite: Set up" >&3 + local os_release="$(find_os_release)" local system_id="$(get_system_id)" local system_version="$(get_system_version)" @@ -42,3 +45,14 @@ load 'libs/helpers' _setup_docker_registry } + +teardown_suite() { + bats_require_minimum_version 1.7.0 + echo "# test suite: Tear down" >&3 + + _setup_environment + + _clean_cached_images + _clean_docker_registry + _clean_temporary_storage +}