Envtest Setup

Learn how to setup your project to run integration tests using envtest

By default, Go-based operators are scaffolded to make use of controller-runtime’s envtest framework, which uses kubectl, kube-apiserver, and etcd to simulate the API portions of a real cluster. You can use this script to download these binaries into the testbin/ directory and configure your environment to use them. Update your Makefile by replacing your test target with:

  1. # Run tests
  2. ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
  3. test: generate fmt vet manifests
  4. mkdir -p ${ENVTEST_ASSETS_DIR}
  5. test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh
  6. source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out

If using git, it is recommended to add testbin/* to your .gitignore file to avoid committing these binaries.

Last modified October 14, 2020: doc: add base doc that clarifies how users can test their projects (#3823) (6eb31294)