From 7e7895c69f22c5b9035c6d3086af9fb765df321b Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 21 Jun 2023 08:04:28 +0200 Subject: [PATCH] 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 --- 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 +}