Skip to content

Commit

Permalink
[chore] Create gotest-with-junit Makefile target (#11963)
Browse files Browse the repository at this point in the history
Creates a target to output junit files from testing. This PR also starts
to use it in CI - we don't consume the Junits yet but it would be easy
to add on. This will be useful for a number of CI/Devx initiatives in
the future.

My company, Datadog, plans to use this information to track the build
stability of our code in contrib, as well as the stability of code we
depend on here in collector.
  • Loading branch information
ankitpatel96 authored Dec 23, 2024
1 parent a573bc9 commit 84fe00d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ jobs:
key: unittest-${{ runner.os }}-${{ matrix.runner }}-go-build-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
- name: Run Unit Tests
run: |
make -j4 gotest
make -j4 gotest-with-junit
- uses: actions/upload-artifact@v4
with:
name: test-results-${{ runner.os }}-${{ matrix.runner }}-${{ matrix.go-version }}
path: internal/tools/testresults/
retention-days: 4
unittest:
if: always()
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ gotest-with-cover:
@$(MAKE) for-all-target TARGET="test-with-cover"
$(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./coverage.txt

.PHONY: gotest-with-junit
gotest-with-junit:
@$(MAKE) for-all-target TARGET="test-with-junit"

.PHONY: gotestifylint-fix
gotestifylint-fix:
$(MAKE) for-all-target TARGET="testifylint-fix"
Expand Down
9 changes: 9 additions & 0 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ALL_PKGS := $(sort $(shell go list ./...))
# COVER_PKGS is the list of packages to include in the coverage
COVER_PKGS := $(shell go list ./... | tr "\n" ",")

CURR_MOD := $(shell go list -m | tr '/' '-' )

GOTEST_TIMEOUT?=240s
GOTEST_OPT?= -race -timeout $(GOTEST_TIMEOUT)
GOCMD?= go
Expand All @@ -19,6 +21,8 @@ TOOLS_MOD_REGEX := "\s+_\s+\".*\""
TOOLS_PKG_NAMES := $(shell grep -E $(TOOLS_MOD_REGEX) < $(TOOLS_MOD_DIR)/tools.go | tr -d " _\"" | grep -vE '/v[0-9]+$$')
TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(shell echo $(TOOLS_PKG_NAMES))))
CHLOGGEN_CONFIG := .chloggen/config.yaml
# no trailing slash
JUNIT_OUT_DIR ?= $(TOOLS_MOD_DIR)/testresults

ADDLICENSE := $(TOOLS_BIN_DIR)/addlicense
APIDIFF := $(TOOLS_BIN_DIR)/apidiff
Expand Down Expand Up @@ -56,6 +60,11 @@ test-with-cover: $(GOTESTSUM)
mkdir -p $(PWD)/coverage/unit
$(GOTESTSUM) --packages="./..." -- $(GOTEST_OPT) -cover -covermode=atomic -coverpkg $(COVER_PKGS) -args -test.gocoverdir="$(PWD)/coverage/unit"

.PHONY: test-with-junit
test-with-junit: $(GOTESTSUM)
mkdir -p $(JUNIT_OUT_DIR)
$(GOTESTSUM) --packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- $(GOTEST_OPT) ./...

.PHONY: benchmark
benchmark: $(GOTESTSUM)
$(GOTESTSUM) --packages="$(ALL_PKGS)" -- -bench=. -run=notests ./... | tee benchmark.txt
Expand Down

0 comments on commit 84fe00d

Please sign in to comment.