From f8e4c1b0ef38d5602fba1a5ecc29b7fe0bdbcc0c Mon Sep 17 00:00:00 2001 From: Sanskar Jaiswal Date: Thu, 13 Jan 2022 14:32:40 +0530 Subject: [PATCH] add comments to targets and cancellable context for tests --- Makefile | 6 +++--- controllers/suite_test.go | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 097d38342..c6763d9c5 100644 --- a/Makefile +++ b/Makefile @@ -176,17 +176,17 @@ controller-gen: ## Download controller-gen locally if necessary. # Find or download gen-crd-api-reference-docs GEN_CRD_API_REFERENCE_DOCS = $(shell pwd)/bin/gen-crd-api-reference-docs .PHONY: gen-crd-api-reference-docs -gen-crd-api-reference-docs: +gen-crd-api-reference-docs: ## Download gen-crd-api-reference-docs locally if necessary $(call go-install-tool,$(GEN_CRD_API_REFERENCE_DOCS),github.com/ahmetb/gen-crd-api-reference-docs@v0.3.0) ENVTEST = $(shell pwd)/bin/setup-envtest .PHONY: envtest -setup-envtest: ## Download envtest-setup locally if necessary. +setup-envtest: ## Download setup-envtest locally if necessary. $(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) ENVTEST_ASSETS_DIR=$(shell pwd)/testbin ENVTEST_KUBERNETES_VERSION?=latest -install-envtest: setup-envtest +install-envtest: setup-envtest ## Download envtest binaries locally. mkdir -p ${ENVTEST_ASSETS_DIR} $(ENVTEST) use $(ENVTEST_KUBERNETES_VERSION) --arch=$(ENVTEST_ARCH) --bin-dir=$(ENVTEST_ASSETS_DIR) diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 5f5341155..9520bcbb6 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -17,6 +17,7 @@ limitations under the License. package controllers import ( + "context" "math/rand" "net/http" "os" @@ -52,6 +53,8 @@ var storage *Storage var examplePublicKey []byte var examplePrivateKey []byte var exampleCA []byte +var ctx context.Context +var cancel context.CancelFunc func TestAPIs(t *testing.T) { RegisterFailHandler(Fail) @@ -65,6 +68,7 @@ var _ = BeforeSuite(func(done Done) { logf.SetLogger( zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)), ) + ctx, cancel = context.WithCancel(context.TODO()) By("bootstrapping test environment") t := true @@ -141,7 +145,8 @@ var _ = BeforeSuite(func(done Done) { Expect(err).ToNot(HaveOccurred(), "failed to setup HelmChartReconciler") go func() { - err = k8sManager.Start(ctrl.SetupSignalHandler()) + defer GinkgoRecover() + err = k8sManager.Start(ctx) Expect(err).ToNot(HaveOccurred()) }() @@ -152,6 +157,7 @@ var _ = BeforeSuite(func(done Done) { }, 60) var _ = AfterSuite(func() { + cancel() By("tearing down the test environment") if storage != nil { err := os.RemoveAll(storage.BasePath)