Skip to content

Commit 012d961

Browse files
authored
Merge pull request #1710 from shiftstack/envtest-data
🌱 Allow custom KUBEBUILDER_ASSETS_DIR in tests
2 parents 4014304 + c076ff9 commit 012d961

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,25 @@ endif
129129
$(ARTIFACTS):
130130
mkdir -p $@
131131

132-
ifeq ($(shell go env GOOS),darwin) # Use the darwin/amd64 binary until an arm64 version is available
133-
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path --arch amd64 $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
134-
else
135-
KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION))
132+
setup_envtest_extra_args=
133+
# Use the darwin/amd64 binary until an arm64 version is available
134+
ifeq ($(shell go env GOOS),darwin)
135+
setup_envtest_extra_args += --arch amd64
136+
endif
137+
138+
# By default setup-envtest will write to $XDG_DATA_HOME, or $HOME/.local/share
139+
# if that is not defined. Set KUBEBUILDER_ASSETS_DIR to override.
140+
ifdef KUBEBUILDER_ASSETS_DIR
141+
setup_envtest_extra_args += --bin-dir $(KUBEBUILDER_ASSETS_DIR)
136142
endif
137143

138144
.PHONY: test
139145
test: $(SETUP_ENVTEST) ## Run tests
140-
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -v ./... $(TEST_ARGS)
146+
set -xeuf -o pipefail; \
147+
if [ -z "$(KUBEBUILDER_ASSETS)" ]; then \
148+
KUBEBUILDER_ASSETS=`$(SETUP_ENVTEST) use --use-env -p path $(setup_envtest_extra_args) $(KUBEBUILDER_ENVTEST_KUBERNETES_VERSION)`; \
149+
fi; \
150+
KUBEBUILDER_ASSETS="$$KUBEBUILDER_ASSETS" go test -v ./... $(TEST_ARGS)
141151

142152
E2E_TEMPLATES_DIR=test/e2e/data/infrastructure-openstack
143153
E2E_KUSTOMIZE_DIR=test/e2e/data/kustomize

0 commit comments

Comments
 (0)