Skip to content

Commit

Permalink
[chore] Use gotestsum wrapper for go tests (#11946)
Browse files Browse the repository at this point in the history
**Description:**

Use
[gotestyourself/gotestsum](https://github.com/gotestyourself/gotestsum?rgh-link-date=2024-02-09T12%3A20%3A03Z)
for running tests.
This is following contrib's lead - they implemented this in this
[PR](open-telemetry/opentelemetry-collector-contrib#31163).

Gotestsum is a lot more readable and user friendly than go test - the
output format is nicer and the test output is more parseable. We could
also use [rerun on
failed](https://github.com/gotestyourself/gotestsum#re-running-failed-tests)
or some of their other features!

---------

Co-authored-by: Pablo Baeyens <[email protected]>
  • Loading branch information
ankitpatel96 and mx-psi authored Dec 18, 2024
1 parent be406d3 commit 1b4e1ee
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ COVER_PKGS := $(shell go list ./... | tr "\n" ",")
GOTEST_TIMEOUT?=240s
GOTEST_OPT?= -race -timeout $(GOTEST_TIMEOUT)
GOCMD?= go
GOTEST=$(GOCMD) test
GOOS := $(shell $(GOCMD) env GOOS)
GOARCH := $(shell $(GOCMD) env GOARCH)

Expand Down Expand Up @@ -37,6 +36,7 @@ MULTIMOD := $(TOOLS_BIN_DIR)/multimod
PORTO := $(TOOLS_BIN_DIR)/porto
SEMCONVGEN := $(TOOLS_BIN_DIR)/semconvgen
SEMCONVKIT := $(TOOLS_BIN_DIR)/semconvkit
GOTESTSUM := $(TOOLS_BIN_DIR)/gotestsum

.PHONY: install-tools
install-tools: $(TOOLS_BIN_NAMES)
Expand All @@ -48,17 +48,17 @@ $(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod
cd $(TOOLS_MOD_DIR) && $(GOCMD) build -o $@ -trimpath $(filter %/$(notdir $@),$(TOOLS_PKG_NAMES))

.PHONY: test
test:
$(GOTEST) $(GOTEST_OPT) ./...
test: $(GOTESTSUM)
$(GOTESTSUM) --packages="./..." -- $(GOTEST_OPT)

.PHONY: test-with-cover
test-with-cover: $(GO_ACC)
test-with-cover: $(GOTESTSUM)
mkdir -p $(PWD)/coverage/unit
$(GOTEST) $(GOTEST_OPT) -cover ./... -covermode=atomic -coverpkg $(COVER_PKGS) -args -test.gocoverdir="$(PWD)/coverage/unit"
$(GOTESTSUM) --packages="./..." -- $(GOTEST_OPT) -cover -covermode=atomic -coverpkg $(COVER_PKGS) -args -test.gocoverdir="$(PWD)/coverage/unit"

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

.PHONY: fmt
fmt: common/gofmt common/goimports common/gofumpt
Expand Down
5 changes: 5 additions & 0 deletions internal/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
golang.org/x/tools v0.28.0
golang.org/x/vuln v1.1.3
gotest.tools/gotestsum v1.12.0
mvdan.cc/gofumpt v0.7.0
)

Expand Down Expand Up @@ -47,6 +48,7 @@ require (
github.com/ashanbrown/forbidigo v1.6.0 // indirect
github.com/ashanbrown/makezero v1.1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bitfield/gotestdox v0.2.2 // indirect
github.com/bkielbasa/cyclop v1.2.3 // indirect
github.com/blizzy78/varnamelen v0.8.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.0.2 // indirect
Expand All @@ -67,6 +69,7 @@ require (
github.com/daixiang0/gci v0.13.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/denis-tingaikin/go-header v0.5.0 // indirect
github.com/dnephin/pflag v1.0.7 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/ettle/strcase v0.2.0 // indirect
github.com/fatih/color v1.18.0 // indirect
Expand Down Expand Up @@ -100,6 +103,7 @@ require (
github.com/golangci/revgrep v0.5.3 // indirect
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gordonklaus/ineffassign v0.1.0 // indirect
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
github.com/gostaticanalysis/comment v1.4.2 // indirect
Expand Down Expand Up @@ -216,6 +220,7 @@ require (
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/telemetry v0.0.0-20240522233618-39ace7a40ae7 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
50 changes: 50 additions & 0 deletions internal/tools/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
_ "golang.org/x/exp/cmd/apidiff"
_ "golang.org/x/tools/cmd/goimports"
_ "golang.org/x/vuln/cmd/govulncheck"
_ "gotest.tools/gotestsum"
_ "mvdan.cc/gofumpt"

_ "go.opentelemetry.io/collector/internal/tools/semconvkit"
Expand Down

0 comments on commit 1b4e1ee

Please sign in to comment.