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:
# Run tests
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests
mkdir -p ${ENVTEST_ASSETS_DIR}
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
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)
当前内容版权归 Operator SDK 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Operator SDK .