Testing

How to run tests

Prerequisites

  • Go distribution
  • If you are on Linux, you will need to install libvirt-dev, since unit tests need kvm2 driver:
  1. # For Debian based
  2. sudo apt-get install libvirt-dev
  3. # For Centos
  4. yum install libvirt-devel
  5. # For Fedora
  6. dnf install libvirt-devel

Unit Tests

Unit tests are run on Travis before code is merged. To run as part of a development cycle:

  1. make test

Integration Tests

The basics

From the minikube root directory, build the binary and run the tests:

  1. make integration

You may find it useful to set various options to test only a particular test against a non-default driver. For instance:

  1. env TEST_ARGS="-minikube-start-args=--driver=hyperkit -test.run TestStartStop" make integration

Quickly iterating on a single test

Run a single test on an active cluster:

  1. make integration -e TEST_ARGS="-test.run TestFunctional/parallel/MountCmd --profile=minikube --cleanup=false"

WARNING: For this to work repeatedly, the test must be written so that it cleans up after itself.

The --cleanup=false test arg ensures that the cluster will not be deleted after the test is run.

See main_test.go for details.

Disabling parallelism

  1. make integration -e TEST_ARGS="-test.parallel=1"

Testing philosophy

  • Tests should be so simple as to be correct by inspection
  • Readers should need to read only the test body to understand the test
  • Top-to-bottom readability is more important than code de-duplication

Tests are typically read with a great air of skepticism, because chances are they are being read only when things are broken.

Conformance Tests

These are Kubernetes tests that run against an arbitrary cluster and exercise a wide range of Kubernetes features. You can run these against minikube by following these steps:

Install docker Install kubectl Clone the minikube repo

Compile the latest minikube binary

  1. % cd <minikube dir>
  2. % make

Trigger the tests and get back the results

  1. % cd <minikube dir>
  2. ./hack/conformance_tests.sh out/minikube --driver=docker --container-runtimer=docker --kubernetes-version=stable

This script will run the latest sonobuoy against a minikube cluster with two nodes and the provided parameters.

Last modified October 27, 2021: update conformance test instructions in documentation (eed2bf69f)