podman/test
OpenShift Merge Robot 747369c82d
Merge pull request #17713 from sbrivio-rh/pasta
pasta: Re-enable "Local forwarder, IPv4" test now that packages in CI images are fixed
2023-03-08 20:22:45 +01:00
..
apiv2 compat API: network create return 409 for duplicate 2023-02-21 16:55:27 +01:00
build
buildah-bud Cirrus: Fix git config permission denied 2023-02-28 10:52:20 -05:00
certs Add new key and never-expiring test certificate 2019-03-20 13:36:17 -04:00
checkseccomp go fmt: use go 1.18 conditional-build syntax 2022-03-18 09:11:53 +01:00
compose compat API: allow MacAddress on container config 2022-12-05 16:52:36 +01:00
e2e Quadlet: add support for setting --ip and --ip6 2023-03-06 18:36:41 -07:00
framework Fix spelling "setup" -> "set up" and similar 2022-06-22 18:39:21 +02:00
goecho Separate common used test functions and structs to test/utils 2018-11-16 10:49:00 +08:00
install Enable pre-commit tool linting 2020-01-14 13:42:59 +00:00
minikube Add podman kube apply command 2022-11-01 15:30:17 -04:00
python Fix typos 2023-02-11 18:23:24 +01:00
system pasta: Re-enable "Local forwarder, IPv4" test, accept NXDOMAIN as response 2023-03-08 17:09:40 +01:00
testvol Replace deprecated ioutil 2022-09-20 15:34:27 -04:00
tools build(deps): bump golang.org/x/tools from 0.6.0 to 0.7.0 in /test/tools 2023-03-08 13:02:30 +00:00
upgrade Fix language. Mostly spelling a -> an 2022-11-20 19:41:06 +01:00
utils ginkgo tests: apply ginkgolinter fixes 2022-12-20 16:47:17 +01:00
version enable staticcheck linter 2022-04-22 12:51:29 +02:00
deny.json Always allow pushing from containers-storage 2022-12-16 14:59:00 -05:00
policy.json
README.md e2e: update test/README.md 2023-01-18 10:35:19 +09:00
redhat_sigstore.yaml
registries.conf container create: fix --tls-verify parsing 2021-10-27 14:36:25 +02:00
test_podman_baseline.sh volume: add new option -o o=noquota 2022-04-28 13:29:01 +02:00
test_podman_build.sh Use bash binary from env instead of /bin/bash for scripts 2020-08-17 10:42:23 +02:00
test_podman_pods.sh Add --time out for podman * rm -f commands 2021-10-04 07:07:56 -04:00

PODMAN logo

Test utils

Test utils provide common functions and structs for testing. It includes two structs:

  • PodmanTest: Handle the podman command and other global resources like temporary directory. It provides basic methods, like checking podman image and pod status. Test suites should create their owner test struct as a composite of PodmanTest, and their owner PodmanMakeOptions().

  • PodmanSession: Store execution session data and related methods. Such like get command output and so on. It can be used directly in the test suite, only embed it to your owner session struct if you need expend it.

Unittest for test/utils

To ensure neither tests nor utils break, There are unit-tests for each functions and structs in test/utils. When you adding functions or structs to this package, please update both unit-tests for it and this documentation.

Run unit test for test/utils

Run unit test for test/utils.

make localunit

Structure of the test utils and test suites

The test utils package is at the same level of test suites. Each test suites also have their owner common functions and structs stored in libpod_suite_test.go.

Ginkgo test framework

Ginkgo is a BDD testing framework. This allows us to use native Golang to perform our tests and there is a strong affiliation between Ginkgo and the Go test framework.

Installing dependencies

The dependencies for integration really consists of three things:

  • ginkgo binary

The following instructions assume your GOPATH is ~/go. Adjust as needed for your environment.

Installing ginkgo

Build ginkgo and install it under $GOPATH/bin with the following commands:

export GOCACHE="$(mktemp -d)"
GOPATH=~/go make .install.ginkgo

If your PATH does not include $GOPATH/bin, you might consider adding it.

PATH=$PATH:$GOPATH/bin

Integration Tests

Test suite for integration test for podman command line. It has its own structs:

  • PodmanTestIntegration: Integration test struct as a composite of PodmanTest. It set up the global options for podman command to ignore the environment influence from different test system.

  • PodmanSessionIntegration: This struct has it own methods for checking command output with given format JSON by using structs defined in inspect package.

Running the integration tests

You can run the entire suite of integration tests with the following command:

GOPATH=~/go ginkgo -tags "remote" -v test/e2e/.

Note the trailing period on the command above. Also, -v invokes verbose mode. That switch is optional.

Running a single file of integration tests

You can run a single file of integration tests using the go test command:

GOPATH=~/go go test -v test/e2e/libpod_suite_test.go test/e2e/common_test.go test/e2e/config.go test/e2e/config_amd64.go test/e2e/your_test.go

If you want to run the tests with the podman-remote client, make sure to replace test/e2e/libpod_suite_test.go with test/e2e/libpod_suite_remote_test.go.

Running a single integration test

Before running the test suite, you have to declare which test you want run in the test file itself. Consider the following actual test:

It("podman inspect bogus pod", func() {
		session := podmanTest.Podman([]string{"pod", "inspect", "foobar"})
		session.WaitWithDefaultTimeout()
		Expect(session).To(ExitWithError())
	})

To mark this as the test you want run, you simply change the It description to FIt. Please note how both the F and I are capitalized.

You can run a single integration test using the same command we used to run all the tests in a single file.

GOPATH=~/go go test -v test/e2e/libpod_suite_test.go test/e2e/common_test.go test/e2e/config.go test/e2e/config_amd64.go test/e2e/your_test.go

Note: Be sure you remove the F from the tests before committing your changes or you will skip all tests in that file except the one with the FIt denotation.

Run tests in a container

In case you have issue running the tests locally on your machine, you can run them in a container:

make shell

This will run a container and give you a shell and you can follow the instructions above.

System tests

System tests are used for testing the podman CLI in the context of a complete system. It requires that podman, all dependencies, and configurations are in place. The intention of system testing is to match as closely as possible with real-world user/developer use-cases and environments. The orchestration of the environments and tests is left to external tooling.

System tests use Bash Automated Testing System (bats) as a testing framework. Install it via your package manager or get latest stable version directly from the repository, e.g.:

mkdir -p ~/tools/bats
git clone --single-branch --branch v1.1.0 https://github.com/bats-core/bats-core.git ~/tools/bats

Make sure that bats binary (bin/bats in the repository) is in your PATH, if not - add it:

PATH=$PATH:~/tools/bats/bin

System tests also rely on jq, socat, nmap, and other tools. For a comprehensive list, see the %package tests section in the fedora specfile.

Running system tests

When bats is installed and is in your PATH, you can run the test suite with following command:

make localsystem

Running the system tests in a more controlled way

If you would like to run a subset of the system tests, or configure the environment (e.g. root vs rootless, local vs remote), use hack/bats.

For usage run:

hack/bats --help

Contributing to system tests

Please see the TODO list of needed workflows/tests.