Skip to content

Commit

Permalink
test/system: Simplify running a subset of the tests with Bats >= 1.7.0
Browse files Browse the repository at this point in the history
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 e22a82f already added a dependency on Bats >= 1.7.0.
Therefore, it should be exploited wherever possible to simplify things.

[1] Commit 54a2ca1
    #751

[2] Bats commit fb467ec3f04e322a
    bats-core/bats-core#39
    https://bats-core.readthedocs.io/en/stable/writing-tests.html
  • Loading branch information
debarshiray committed Jun 21, 2023
1 parent 647b1f4 commit 7e7895c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
26 changes: 0 additions & 26 deletions test/system/999-teardown.bats

This file was deleted.

16 changes: 15 additions & 1 deletion test/system/000-setup.bats → test/system/setup_suite.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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
}

0 comments on commit 7e7895c

Please sign in to comment.