k3s/tests/integration
Brad Davidson 418c3fa858
Fix issue with datastore corruption on cluster-reset (#5515)
* Bump etcd to v3.5.4-k3s1
* Fix issue with datastore corruption on cluster-reset
* Disable unnecessary components during cluster reset

Disable control-plane components and the tunnel setup during
cluster-reset, even when not doing a restore. This reduces the amount of
log clutter during cluster reset/restore, making any errors encountered
more obvious.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2022-04-27 13:44:15 -07:00
..
certrotation Add certificate rotation integration tests (#5393) 2022-04-08 20:03:31 +02:00
custometcdargs Testing directory and documentation rework. (#5256) 2022-03-15 10:29:56 -07:00
dualstack Testing directory and documentation rework. (#5256) 2022-03-15 10:29:56 -07:00
etcdrestore Fix issue with datastore corruption on cluster-reset (#5515) 2022-04-27 13:44:15 -07:00
etcdsnapshot Testing directory and documentation rework. (#5256) 2022-03-15 10:29:56 -07:00
localstorage Testing directory and documentation rework. (#5256) 2022-03-15 10:29:56 -07:00
secretsencryption Bump Reencryption Test timeout, improve comments (#5431) 2022-04-14 11:46:37 -07:00
Dockerfile.test [master] changing package to k3s-io (#4846) 2022-03-02 15:47:27 -08:00
README.md Testing directory and documentation rework. (#5256) 2022-03-15 10:29:56 -07:00
integration.go Bump Reencryption Test timeout, improve comments (#5431) 2022-04-14 11:46:37 -07:00
test-runner.sh Creation of K3s integration test Sonobuoy plugin (#3931) 2021-08-30 08:27:59 -07:00

README.md

Integration Tests

Integration tests should be used to test a specific functionality of k3s that exists across multiple Go packages, either via exported function calls, or more often, CLI comands. Integration tests should be used for "black box" testing.

Framework

All integration tests in K3s follow a Behavior Diven Development (BDD) style. Specifically, K3s uses Ginkgo and Gomega to drive the tests.
To generate an initial test, the command ginkgo bootstrap can be used.

To facilitate K3s CLI testing, see tests/util/cmd.go helper functions.

Format

All integration tests should be placed under tests/integration/<TEST_NAME>.
All integration test files should be named: <TEST_NAME>_int_test.go.
All integration test functions should be named: Test_Integration<TEST_NAME>.
See the local storage test as an example.

Running

Integration tests can be run with no k3s cluster present, each test will spin up and kill the appropriate k3s server it needs.
Note: Integration tests must be run as root, prefix the commands below with sudo -E env "PATH=$PATH" if a sudo user.

go test ./tests/integration/... -run Integration

Additionally, to generate JUnit reporting for the tests, the Ginkgo CLI is used

ginkgo --junit-report=result.xml ./tests/integration/...

Integration tests can be run on an existing single-node cluster via compile time flag, tests will skip if the server is not configured correctly.

go test -ldflags "-X 'github.com/k3s-io/k3s/tests/integration.existingServer=True'" ./tests/integration/... -run Integration

Integration tests can also be run via a Sonobuoy plugin on an existing single-node cluster.

./scripts/build-tests-sonobuoy
sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml sonobuoy run --plugin ./dist/artifacts/k3s-int-tests.yaml

Check the sonobuoy status and retrieve results

sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml sonobuoy status
sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml sonobuoy retrieve
sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml sonobuoy results <TAR_FILE_FROM_RETRIEVE>