Skip to content

Commit 5f44794

Browse files
prerequisites for running the unit tests (#669)
Signed-off-by: Prajyot-Parab <[email protected]> Co-authored-by: Prajyot-Parab <[email protected]>
1 parent e2d094b commit 5f44794

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ ENVSUBST := $(TOOLS_BIN_DIR)/envsubst
3838
MOCKGEN := $(TOOLS_BIN_DIR)/mockgen
3939
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
4040
CONVERSION_VERIFIER := $(TOOLS_BIN_DIR)/conversion-verifier
41+
SETUP_ENVTEST := $(TOOLS_BIN_DIR)/setup-envtest
4142

4243
STAGING_REGISTRY ?= gcr.io/k8s-staging-capi-ibmcloud
4344
STAGING_BUCKET ?= artifacts.k8s-staging-capi-ibmcloud.appspot.com
@@ -54,6 +55,8 @@ ARCH ?= amd64
5455
ALL_ARCH ?= amd64 ppc64le
5556
PULL_POLICY ?= Always
5657

58+
KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.23.3
59+
5760
# main controller
5861
CORE_IMAGE_NAME ?= cluster-api-ibmcloud-controller
5962
CORE_CONTROLLER_IMG ?= $(REGISTRY)/$(CORE_IMAGE_NAME)
@@ -160,9 +163,19 @@ lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported
160163
## Testing
161164
## --------------------------------------
162165

166+
.PHONY: setup-envtest
167+
setup-envtest: $(SETUP_ENVTEST) # Build setup-envtest from tools folder.
168+
@if [ $(shell go env GOOS) == "darwin" ]; then \
169+
$(eval KUBEBUILDER_ASSETS := $(shell $(SETUP_ENVTEST) use --use-env -p path --arch amd64 $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))) \
170+
echo "kube-builder assets set using darwin OS"; \
171+
else \
172+
$(eval KUBEBUILDER_ASSETS := $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))) \
173+
echo "kube-builder assets set using other OS"; \
174+
fi
175+
163176
# Run unit tests
164-
test: generate fmt vet manifests
165-
go test ./... -coverprofile cover.out
177+
test: generate fmt vet manifests setup-envtest ## Run tests
178+
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... -coverprofile cover.out
166179

167180
# Allow overriding the e2e configurations
168181
GINKGO_FOCUS ?= Workload cluster creation

hack/tools/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ $(CONTROLLER_GEN): $(BIN_DIR) go.mod go.sum
9898
CONVERSION_VERIFIER := $(BIN_DIR)/conversion-verifier
9999
$(CONVERSION_VERIFIER): $(BIN_DIR) go.mod go.sum
100100
go build -tags=tools -o $@ sigs.k8s.io/cluster-api/hack/tools/conversion-verifier
101+
102+
SETUP_ENVTEST := $(BIN_DIR)/setup-envtest
103+
$(SETUP_ENVTEST): $(BIN_DIR) go.mod go.sum
104+
go build -tags=tools -o $@ sigs.k8s.io/controller-runtime/tools/setup-envtest

0 commit comments

Comments
 (0)