Skip to content

Commit dc5721c

Browse files
(fix): Make test-unit target execution on macOS by disabling CGO_ENABLED
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
1 parent 32498f1 commit dc5721c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,15 @@ test-ext-dev-e2e: $(OPERATOR_SDK) $(KUSTOMIZE) $(KIND) #HELP Run extension creat
152152
go test -count=1 -v ./test/extension-developer-e2e/...
153153

154154
.PHONY: test-unit
155+
# Define CGO_ENABLED based on the OS
156+
CGO_ENABLED_VAL := $(if $(filter Linux, $(shell uname)),1,0)
155157
ENVTEST_VERSION := $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
156158
UNIT_TEST_DIRS := $(shell go list ./... | grep -v /test/)
157159
COVERAGE_UNIT_DIR := $(ROOT_DIR)/coverage/unit
158160
test-unit: $(SETUP_ENVTEST) #HELP Run the unit tests
159161
rm -rf $(COVERAGE_UNIT_DIR) && mkdir -p $(COVERAGE_UNIT_DIR)
160162
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION) $(SETUP_ENVTEST_BIN_DIR_OVERRIDE)) && \
161-
CGO_ENABLED=1 go test \
163+
CGO_ENABLED=$(CGO_ENABLED_VAL) go test \
162164
-tags '$(GO_BUILD_TAGS)' \
163165
-cover -coverprofile ${ROOT_DIR}/coverage/unit.out \
164166
-count=1 -race -short \

0 commit comments

Comments
 (0)