k3s/tests/integration
Brad Davidson ae59cd0173
Some checks failed
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Install Script / build (push) Has been cancelled
Install Script / Smoke Test (push) Has been cancelled
Add tests for etcd local reconcile
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2026-01-05 09:59:29 -08:00
..
cacertrotation Fix caceertrotation test; add kine to matrix 2025-09-05 17:07:43 +00:00
certrotation Consolidate test utility functions into top level package (#11711) 2025-02-04 17:23:18 -08:00
custometcdargs Add integration tests for etc-snapshot server flags and refactor /tests/integration/integration.go/K3sStartServer (#7300) 2023-04-28 14:07:11 -03:00
dualstack Consolidate test utility functions into top level package (#11711) 2025-02-04 17:23:18 -08:00
etcdrestore Consolidate test utility functions into top level package (#11711) 2025-02-04 17:23:18 -08:00
etcdsnapshot Consolidate test utility functions into top level package (#11711) 2025-02-04 17:23:18 -08:00
flannelipv6masq Consolidate test utility functions into top level package (#11711) 2025-02-04 17:23:18 -08:00
flannelnone Fix pods readiness tests 2025-09-18 16:31:15 -07:00
kubeflags Inclusive naming proposal (issue: #12110, Orlin Vasiliev) (#12383) 2025-09-24 08:52:28 -07:00
localstorage Consolidate test utility functions into top level package (#11711) 2025-02-04 17:23:18 -08:00
longhorn Fix pods readiness tests 2025-09-18 16:31:15 -07:00
secretsencryption Consolidate test utility functions into top level package (#11711) 2025-02-04 17:23:18 -08:00
startup Add tests for etcd local reconcile 2026-01-05 09:59:29 -08:00
Dockerfile.test Bump golang to 1.18.1 2022-05-11 14:39:07 -07:00
integration.go Fix pods readiness tests 2025-09-18 16:31:15 -07:00
README.md Update localstorage_int_test.go reference (#11339) 2024-11-19 10:35:31 -08:00
test-runner.sh Creation of K3s integration test Sonobuoy plugin (#3931) 2021-08-30 08:27:59 -07:00

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 commands. 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 -ginkgo.v -test.v

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 -ginkgo.v -test.v

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>