From 6dd929086b442d696d66233dcc6a417d2fdbd3ad Mon Sep 17 00:00:00 2001 From: Adam Kaplan Date: Thu, 2 Nov 2023 15:35:12 -0400 Subject: [PATCH] Skip EnvTest Tests Add option to skip the reconcile tests that utilize EnvTest. These tests have a noticeable amout of setup time, and failure cases can take over 30 seconds each to be identified due to timeouts. The skip option will execute test cases that do not require EnvTest, which are more likely to be standard golang unit tests that execute quickly. This also drops the `-p 1` parameter passed to `go test`, which allows go to execute tests in parallel. --- Makefile | 6 ++++-- controllers/suite_test.go | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e5229890..94de2780 100644 --- a/Makefile +++ b/Makefile @@ -133,10 +133,12 @@ verify-fmt: fmt ## Verify formatting and ensure git status is clean vet: ## Run go vet against code. go vet ./... +SKIP_ENVTEST ?= false + BINDATA = $(shell pwd)/kodata .PHONY: test -test: manifests generate fmt vet envtest ## Run tests. - KO_DATA_PATH=${BINDATA} KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out -p 1 -failfast -test.v -test.failfast +test: manifests generate fmt vet envtest ## Run tests. To bypass longer-running reconcile tests with EnvTest, set SKIP_ENVTEST=true. + KO_DATA_PATH=${BINDATA} KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" SKIP_ENVTEST=${SKIP_ENVTEST} go test ./... -coverprofile cover.out -failfast -test.v -test.failfast ##@ Build diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 0d5bbbee..b5b64315 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -6,7 +6,9 @@ package controllers import ( "context" + "os" "path/filepath" + "strconv" "testing" "time" @@ -42,6 +44,11 @@ var ( ) func TestAPIs(t *testing.T) { + skip := os.Getenv("SKIP_ENVTEST") + shouldSkip, _ := strconv.ParseBool(skip) + if shouldSkip { + t.Skip("bypassing Ginkgo-driven tests") + } RegisterFailHandler(Fail) SetDefaultEventuallyTimeout(restTimeout) SetDefaultEventuallyPollingInterval(restRetry)