Some tests interact with the kvstore and depend on a local kvstore instances of etcd. To start the local instances, run:
$ make start-kvstores
Running all tests¶
To run integration tests over the entire repository, run the following command in the project root directory:
$ make integration-tests
To run just unit tests, run:
$ go test ./...
Testing individual packages¶
It is possible to test individual packages by invoking
go test directly.
You can then
cd into the package subject to testing and invoke go test:
$ cd pkg/kvstore $ go test
If you need more verbose output, you can pass in the
$ cd pkg/kvstore $ go test -check.v -check.vv
Integration tests have some prerequisites like Prerequisites, you can use the following command to automatically set up the prerequisites, run the unit tests and tear down the prerequisites:
$ make integration-tests TESTPKGS=pkg/kvstore
Some packages have privileged tests. They are not run by default when you run the integration tests for the respective package. The privileged test files have an entry at the top of the test file as shown.
There are two ways that you can run the ‘privileged’ tests.
To run all the ‘privileged’ tests for cilium follow the instructions below.
$ sudo -E make tests-privileged
To run a specific package ‘privileged’ test, follow the instructions below. Here for example we are trying to run the tests for ‘routing’ package.
$ TESTPKGS="pkg/aws/eni/routing" sudo -E make tests-privileged
Running individual tests¶
Due to the use of gocheck, the standard
go test -run will not work,
-check.f argument has to be specified:
$ go test -check.f TestParallelAllocation
Automatically run unit tests on code changes¶
contrib/shell/test.sh contains some helpful bash functions to
improve the feedback cycle between writing tests and seeing their results. If
you’re writing unit tests in a particular package, the
will watch for changes in a directory and run the unit tests for that package
any time the files change. For example, if writing unit tests in
run this in a terminal next to your editor:
$ . contrib/shell/test.sh $ watchtest pkg/policy
This shell script depends on the
inotify-tools package on Linux.