Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prerequisites for running the unit tests #667

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ENVSUBST := $(TOOLS_BIN_DIR)/envsubst
MOCKGEN := $(TOOLS_BIN_DIR)/mockgen
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
CONVERSION_VERIFIER := $(TOOLS_BIN_DIR)/conversion-verifier
SETUP_ENVTEST := $(TOOLS_BIN_DIR)/setup-envtest

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

KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.23.3

# main controller
CORE_IMAGE_NAME ?= cluster-api-ibmcloud-controller
CORE_CONTROLLER_IMG ?= $(REGISTRY)/$(CORE_IMAGE_NAME)
Expand Down Expand Up @@ -160,9 +163,19 @@ lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported
## Testing
## --------------------------------------

.PHONY: setup-envtest
setup-envtest: $(SETUP_ENVTEST) # Build setup-envtest from tools folder.
@if [ $(shell go env GOOS) == "darwin" ]; then \
$(eval KUBEBUILDER_ASSETS := $(shell $(SETUP_ENVTEST) use --use-env -p path --arch amd64 $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))) \
echo "kube-builder assets set using darwin OS"; \
else \
$(eval KUBEBUILDER_ASSETS := $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))) \
echo "kube-builder assets set using other OS"; \
fi

# Run unit tests
test: generate fmt vet manifests
go test ./... -coverprofile cover.out
test: generate fmt vet manifests setup-envtest ## Run tests
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... -coverprofile cover.out

# Allow overriding the e2e configurations
GINKGO_FOCUS ?= Workload cluster creation
Expand Down
4 changes: 4 additions & 0 deletions hack/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,7 @@ $(CONTROLLER_GEN): $(BIN_DIR) go.mod go.sum
CONVERSION_VERIFIER := $(BIN_DIR)/conversion-verifier
$(CONVERSION_VERIFIER): $(BIN_DIR) go.mod go.sum
go build -tags=tools -o $@ sigs.k8s.io/cluster-api/hack/tools/conversion-verifier

SETUP_ENVTEST := $(BIN_DIR)/setup-envtest
$(SETUP_ENVTEST): $(BIN_DIR) go.mod go.sum
go build -tags=tools -o $@ sigs.k8s.io/controller-runtime/tools/setup-envtest