Unit tests should be written when a component or function of a package needs testing.
Unit tests should be used for "white box" testing.
### Framework
All unit tests in K3s follow a [Table Driven Test](https://github.com/golang/go/wiki/TableDrivenTests) style. Specifically, K3s unit tests are automatically generated using the [gotests](https://github.com/cweill/gotests) tool. This is built into the Go vscode extension, has documented integrations for other popular editors, or can be run via command line. Additionally, a set of custom templates are provided to extend the generated test's functionality. To use these templates, call:
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.
Smoke tests are a collection of tests defined under the [tests](./tests) and fall into two categories: install and snapshotter. These tests are used to validate the installation and operation of K3s on a variety of operating systems. The sub-directories therein contain fixtures for running simple clusters to assert correct behavior for "happy path" scenarios. The test themses are Vagrantfiles describing single-node installations that are easily spun up with Vagrant for the `libvirt` and `virtualbox` providers:
- [Install Script](install) :arrow_right: scheduled nightly and on an install script change
- [CentOS 7](install/centos-7) (stand-in for RHEL 7)
- [Rocky Linux 8](install/rocky-8) (stand-in for RHEL 8)
- [Rocky Linux 9](install/rocky-9) (stand-in for RHEL 9)
- [Fedora 37](install/fedora)
- [Leap 15.5](install/opensuse-leap) (stand-in for SLES)
- [Ubuntu 22.04](install/ubuntu-2204)
- [Snapshotter](snapshotter/btrfs/opensuse-leap) :arrow_right: on any code change
The `libvirt`provider cannot be used without first [installing the `vagrant-libvirt` plugin](https://github.com/vagrant-libvirt/vagrant-libvirt). Libvirtd service must be installed and running on the host machine as well.
Additionally, the `vagrant-scp` and `vagrant-k3s` plugins are required.
E2E tests cover multi-node K3s configuration and administration: bringup, update, teardown etc. across a wide range of operating systems. E2E tests are run nightly as part of K3s quality assurance (QA).
The acceptance tests from distros test framework are a customizable way to create clusters and perform validations on them such that the requirements of specific features and functions can be validated.
See [distros-test-framework/README](https://github.com/rancher/distros-test-framework#readme) for more info.