Skip to content

Commit

Permalink
add comments to targets and cancellable context for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanskar Jaiswal committed Jan 13, 2022
1 parent df964cd commit f8e4c1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package controllers

import (
"context"
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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())
}()

Expand All @@ -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)
Expand Down

0 comments on commit f8e4c1b

Please sign in to comment.