Skip to content

Commit

Permalink
(fix): Make test-unit target execution on macOS by disabling CGO_ENABLED
Browse files Browse the repository at this point in the history
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
  • Loading branch information
camilamacedo86 committed Nov 13, 2024
1 parent 32498f1 commit dc5721c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit dc5721c

Please sign in to comment.