Skip to content

Commit

Permalink
Add support for tparse in go test targets
Browse files Browse the repository at this point in the history
Expand the integration-tests and privileged-tests targets to optionally
run the output through tparse for a friendlier testing experience.
Install this by default in Travis as well so that the format is more
readable in that environment, and add it to the dev-doctor to help teach
developers how to get this output format when running tests like this.

This mode supports a few options:
* Don't install tparse. This is fine, just output to the terminal.
* Install tparse, verbose mode. Output all test output to the terminal
  while the tests are running. Summarize afterwards using tparse.
* Install tparse, quiet mode (V=0). Only output the summary once all of
  the tests have run.

This support is not extended to the benchmark targets so far, as it
seemed like the tparse format doesn't summarize go bench results so this
will only make it more difficult to see the benchmark results.

Suggested-by: Aditi Ghag <aditi@cilium.io>
Signed-off-by: Joe Stringer <joe@cilium.io>
  • Loading branch information
joestringer committed Jun 10, 2022
1 parent a6c227a commit 0b7ef45
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ install_clang
export PATH="/usr/local/clang/bin:$PATH"

go install github.com/mattn/goveralls@a36c7ef8f23b2952fa6e39663f52107dfc8ad69d # v0.0.11
go install github.com/mfridman/tparse@a20c511a88b880dc2544d77d8bc2cc66a8dec507 # v0.10.3
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ tests-privileged:
PATH=$(PATH):$(ROOT_DIR)/bpf $(GO_TEST) $(TEST_LDFLAGS) $$pkg $(GOTEST_UNIT_BASE) $(GOTEST_COVER_OPTS) -coverpkg $$pkg \
|| exit 1; \
tail -n +2 coverage.out >> coverage-all-tmp.out; \
done
done | $(GOTEST_FORMATTER)
$(MAKE) generate-cov

start-kvstores: ## Start running kvstores required for running Cilium integration-tests. More specifically this will run etcd and consul containers.
Expand Down Expand Up @@ -202,7 +202,7 @@ endif
$(GO_TEST) $(TEST_UNITTEST_LDFLAGS) $$pkg $(GOTEST_BASE) $(GOTEST_COVER_OPTS) -coverpkg $$pkg \
|| exit 1; \
tail -n +2 coverage.out >> coverage-all-tmp.out; \
done
done | $(GOTEST_FORMATTER)
$(MAKE) generate-cov
$(MAKE) stop-kvstores

Expand Down
12 changes: 12 additions & 0 deletions Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ GO_TAGS_FLAGS = osusergo
# RACE is specified.
GOTEST_COVER_OPTS =

# By default, just print go test output immediately to the terminal. If tparse
# is installed, use it to format the output. This is either silent silent (V=0)
# or gives some signal about ongoing progress by teeing to the terminal (V=1).
GOTEST_FORMATTER ?= cat
ifneq ($(shell which tparse),)
GOTEST_COVER_OPTS += -json
GOTEST_FORMATTER = tparse
ifneq ($(V),0)
GOTEST_FORMATTER += -follow
endif
endif

GOLANGCILINT_WANT_VERSION = 1.46.2
GOLANGCILINT_IMAGE_SHA = sha256:e84b639c061c8888be91939c78dae9b1525359954e405ab0d9868a46861bd21b
GOLANGCILINT_VERSION = $(shell golangci-lint version 2>/dev/null)
Expand Down
7 changes: 7 additions & 0 deletions tools/dev-doctor/rootcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func rootCmdRun(cmd *cobra.Command, args []string) {
versionRegexp: regexp.MustCompile(`go version go(\d+\.\d+\S*)`),
minVersion: &minGoVersion,
},
&binaryCheck{
name: "tparse",
ifNotFound: checkWarning,
versionArgs: []string{"-v"},
versionRegexp: regexp.MustCompile(`tparse version: v(\d+\.\d+\.\d+)`),
hint: `Run "go install github.com/mfridman/tparse@latest"`,
},
&binaryCheck{
name: "clang",
ifNotFound: checkError,
Expand Down

0 comments on commit 0b7ef45

Please sign in to comment.