You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
k3s/tests/integration
Emmanuel Ferdman 59707dab3d
Update `localstorage_int_test.go` reference (#11339)
5 days ago
..
cacertrotation Add ca-cert rotation integration test 2 months ago
certrotation Containerd restart testlet (#6696) 2 years ago
custometcdargs Add integration tests for etc-snapshot server flags and refactor /tests/integration/integration.go/K3sStartServer (#7300) 2 years ago
dualstack Add int test for flannel-ipv6masq 2 months ago
etcdrestore Fix etcd snapshot integration tests 1 year ago
etcdsnapshot Move etcd snapshot management CLI to request/response 8 months ago
flannelipv6masq Add int test for flannel-ipv6masq 2 months ago
flannelnone Add an integration test for flannel-backend=none 9 months ago
kubeflags Fix CloudDualStackNodeIPs feature-gate inconsistency 1 year ago
localstorage local-storage: Fix permission (#7217) 2 years ago
longhorn Test Coverage Reports for E2E tests (#7526) 1 year ago
secretsencryption [v1.28] CLI Removal for v1.28.0 (#8203) 1 year ago
startup Add tls for kine 8 months ago
Dockerfile.test Bump golang to 1.18.1 3 years ago
README.md Update `localstorage_int_test.go` reference (#11339) 5 days ago
integration.go Add ca-cert rotation integration test 2 months ago
test-runner.sh Creation of K3s integration test Sonobuoy plugin (#3931) 3 years ago

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 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>