toolbox/test/system
Debarshi Ray 7a387dcc8b 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 e22a82fec8 already added a dependency on Bats >= 1.7.0.
Therefore, it should be exploited wherever possible to simplify things.

[1] Commit 54a2ca1ead
    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
2023-06-21 09:07:29 +02:00
..
libs pkg/utils: Offer built-in support for Arch Linux 2023-06-12 22:26:46 +02:00
001-version.bats test/system: Fix warnings by specifying the minimum needed Bats version 2023-06-13 12:48:11 +02:00
002-help.bats doc, test/system: Fix the titles of the manuals 2023-01-12 18:45:00 +01:00
101-create.bats pkg/utils: Offer built-in support for Arch Linux 2023-06-12 22:26:46 +02:00
102-list.bats pkg/utils: Offer built-in support for Arch Linux 2023-06-12 22:26:46 +02:00
103-container.bats test/system: Test a container with an old forward incompatible runtime 2022-12-07 13:03:09 +01:00
104-run.bats test/system: Fix warnings by specifying the minimum needed Bats version 2023-06-13 12:48:11 +02:00
105-enter.bats test/system: Add copyright and license notices 2022-11-29 13:54:13 +01:00
106-rm.bats test/system: Add copyright and license notices 2022-11-29 13:54:13 +01:00
107-rmi.bats test/system: Simplify the line count checks by relying on Bats >= 1.7.0 2023-06-13 12:43:14 +02:00
108-completion.bats test/system: Fix warnings by specifying the minimum needed Bats version 2023-06-13 12:48:11 +02:00
README.md test/system: Replace fedora-toolbox:32 with fedora-toolbox:34 2022-12-07 12:56:41 +01:00
setup_suite.bash test/system: Simplify running a subset of the tests with Bats >= 1.7.0 2023-06-21 09:07:29 +02:00

System tests

These tests are built with BATS (Bash Automated Testing System).

The tests are meant to ensure that Toolbox's functionality remains stable throughout updates of both Toolbox and Podman/libpod.

The tests are set up in a way that does not affect the host environment. Running them won't remove any existing containers or images.

Dependencies

  • awk
  • bats
  • GNU coreutils
  • httpd-tools
  • openssl
  • podman
  • skopeo
  • toolbox

These tests use a few standard libraries for bats which help with clarity and consistency. The libraries are bats-support and bats-assert. These libraries are provided as git submodules in the libs directory. Make sure both are present.

How to run the tests

First, make sure you have all the dependencies installed.

  • Enter the toolbox root folder
  • Invoke command bats ./test/system/ and the test suite should fire up

Mocking of images is done automatically to prevent potential networking issues and to speed up the cases.

By default the test suite uses the system versions of podman, skopeo and toolbox.

If you have a podman, skopeo or toolbox installed in a nonstandard location then you can use the PODMAN, SKOPEO and TOOLBOX environmental variables to set the path to the binaries. So the command to invoke the test suite could look something like this: PODMAN=/usr/libexec/podman TOOLBOX=./toolbox bats ./test/system/.

When running the tests, make sure the test suite: [job] jobs are successful. These jobs set up the whole environment and are a strict requirement for other jobs to run correctly.

Writing tests

Environmental variables

  • Inspect top part of libs/helpers.bats for a list of helper environmental variables

Naming convention

  • All tests should follow the nomenclature: [command]: <test description>...
  • When the test is expected to fail, start the test description with "Try to..."
  • When the test is to give a non obvious output, it should be put in parenthesis at the end of the title

Examples:

  • @test "create: Create the default container"
  • @test "rm: Try to remove a non-existent container"

Test case environment

  • All the tests start with a clean system (no images or containers) to make sure that there are no dependencies between tests and they are really isolated. Use the setup() and teardown() functions for that purpose.

Image registry

  • The system tests set up an OCI image registry for testing purposes - localhost:50000. The registry requires authentication. There is one account present: user (password: user)

  • The registry contains by default only one image: fedora-toolbox:34

Example pull of the fedora-toolbox:34 image:

$PODMAN login --username user --password user "$DOCKER_REG_URI"
$PODMAN pull "$DOCKER_REG_URI/fedora-toolbox:34"