Skip to content

Commit

Permalink
Make sure that we run all go tests in the project
Browse files Browse the repository at this point in the history
  • Loading branch information
andream16 committed Jan 17, 2025
1 parent 6a2238e commit 1b15558
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ protos=$(shell find . -not -path './vendor/*' -name '*.proto')
go_protos=$(protos:.proto=.pb.go)
latest_tag=$(shell git tag --list --sort="-version:refname" | head -n 1)
commits_since_latest_tag=$(shell git log --oneline $(latest_tag)..HEAD | wc -l)
GO_TEST_PACKAGES=$(shell go list ./... | grep -v /vendor/)
# /components/producers/golang-nancy/examples is ignored as it's an example of a vulnerable go.mod.
GO_TEST_PACKAGES=$(shell find . -path './components/producers/golang-nancy/examples' -prune -o -name 'go.mod' -exec dirname {} \; | sort -u)
VENDOR_DIRS=$(shell find . -type d -name "vendor")
NOT_VENDOR_PATHS := $(shell echo $(VENDOR_DIRS) | awk '{for (i=1; i<=NF; i++) print "-not -path \""$$i"/*\""}' | tr '\n' ' ')
EXCLUDE_VENDOR_PATHS := $(shell echo $(VENDOR_DIRS) | awk '{for (i=1; i<=NF; i++) print "--exclude-path \""$$i"\""}' | tr '\n' ' ')
GO_TEST_OUT_DIR_PATH=$(shell pwd)/tests/output

# Deployment vars
# The following variables are used to define the deployment environment
Expand Down Expand Up @@ -133,7 +135,13 @@ install-go-test-tools:

go-tests:
@mkdir -p tests/output
@gotestsum --junitfile tests/output/unit-tests.xml -- -race -coverprofile tests/output/cover.out $(GO_TEST_PACKAGES)
@for package in $(GO_TEST_PACKAGES); do \
LISTED_PACKAGES=./...; \
if [ "$$package" = "." ]; then \
LISTED_PACKAGES=$$(go list ./... | grep -v "^$$package$$"); \
fi; \
(cd $$package && gotestsum --junitfile $(GO_TEST_OUT_DIR_PATH)/unit-tests.xml -- -race -coverprofile $(GO_TEST_OUT_DIR_PATH)/cover.out $$LISTED_PACKAGES) || exit 1; \
done

go-cover: go-tests
@go tool cover -html=tests/output/cover.out -o=tests/output/cover.html && open tests/output/cover.html
Expand Down

0 comments on commit 1b15558

Please sign in to comment.