From dc5721c1fee89d4e1cb8cbf9267beee620c89579 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Wed, 13 Nov 2024 11:36:33 +0000 Subject: [PATCH] (fix): Make test-unit target execution on macOS by disabling CGO_ENABLED MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Linux environments, it is necessary to set `CGO_ENABLED=1` for running unit tests with the `-race` flag. However, enabling CGO_ENABLED on macOS can lead to issues, including warnings such as: ``` ld: warning: ‘/private/var/folders/xf/_py4d4yn7qqdlr5pym3pxvnc0000gn/T/go-link-38050737/000012.o’ has malformed LC_DYSYMTAB, expected 98 undefined symbols to start at index 1626, found 95 undefined symbols starting at index 1626 ``` By disabling it all works fine. PS.: we do not enable CGO for our builds --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5e8033f51..1ac9cdfe1 100644 --- a/Makefile +++ b/Makefile @@ -152,13 +152,15 @@ test-ext-dev-e2e: $(OPERATOR_SDK) $(KUSTOMIZE) $(KIND) #HELP Run extension creat go test -count=1 -v ./test/extension-developer-e2e/... .PHONY: test-unit +# Define CGO_ENABLED based on the OS +CGO_ENABLED_VAL := $(if $(filter Linux, $(shell uname)),1,0) ENVTEST_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/') UNIT_TEST_DIRS := $(shell go list ./... | grep -v /test/) COVERAGE_UNIT_DIR := $(ROOT_DIR)/coverage/unit test-unit: $(SETUP_ENVTEST) #HELP Run the unit tests rm -rf $(COVERAGE_UNIT_DIR) && mkdir -p $(COVERAGE_UNIT_DIR) eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)) && \ - CGO_ENABLED=1 go test \ + CGO_ENABLED=$(CGO_ENABLED_VAL) go test \ -tags '$(GO_BUILD_TAGS)' \ -cover -coverprofile ${ROOT_DIR}/coverage/unit.out \ -count=1 -race -short \