Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use gotestfmt instead of tparse #1788

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/test-hack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ jobs:
- name: dependencies
run: |
make proto/deps
- name: Run tests for hack packages / tparse
- name: Run tests for hack packages / gotestfmt
run: |
make test/cmd/tparse | tee tparse.txt || cat tparse.txt
- name: Run tests for hack packages
TEST_RESULT_DIR=${GITHUB_WORKSPACE} make test/hack/gotestfmt
- name: print tparse result
run: |
make test/cmd
tparse -notests -smallscreen -sort cover -format markdown -file ${GITHUB_WORKSPACE}/test-hack-gotestfmt-result.json
24 changes: 12 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ jobs:
- name: set git config
run: |
git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: Run tests for cmd packages / tparse
- name: Run tests for cmd packages / gotestfmt
run: |
make test/cmd/tparse | tee tparse.txt || cat tparse.txt
- name: Run tests for cmd packages
TEST_RESULT_DIR=${GITHUB_WORKSPACE} make test/cmd/gotestfmt
- name: print tparse result
run: |
make test/cmd
tparse -notests -smallscreen -sort cover -format markdown -file "${GITHUB_WORKSPACE}/test-cmd-gotestfmt-result.json"
test-internal:
name: Run tests for internal packages
runs-on: ubuntu-latest
Expand All @@ -63,12 +63,12 @@ jobs:
- name: set git config
run: |
git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: Run tests for internal packages / tparse
- name: Run tests for internal packages / gotestfmt
run: |
make test/internal/tparse | tee tparse.txt || cat tparse.txt
- name: Run tests for internal packages
TEST_RESULT_DIR=${GITHUB_WORKSPACE} make test/internal/gotestfmt
- name: print tparse result
run: |
make test/internal
tparse -notests -smallscreen -sort cover -format markdown -file "${GITHUB_WORKSPACE}/test-internal-gotestfmt-result.json"
test-pkg:
name: Run tests for pkg packages
runs-on: ubuntu-latest
Expand All @@ -80,9 +80,9 @@ jobs:
- name: set git config
run: |
git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: Run tests for pkg packages / tparse
- name: Run tests for pkg packages / gotestfmt
run: |
make test/pkg/tparse | tee tparse.txt || cat tparse.txt
- name: Run tests for pkg packages
TEST_RESULT_DIR=${GITHUB_WORKSPACE} make test/pkg/gotestfmt
- name: print tparse result
run: |
make test/pkg
tparse -notests -smallscreen -sort cover -format markdown -file "${GITHUB_WORKSPACE}/test-pkg-gotestfmt-result.json"
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ E2E_TARGET_NAMESPACE ?= default
E2E_TARGET_PORT ?= 8081
E2E_PORTFORWARD_ENABLED ?= true

TEST_RESULT_DIR ?= /tmp

include Makefile.d/functions.mk

.PHONY: maintainer
Expand Down
198 changes: 153 additions & 45 deletions Makefile.d/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,177 @@
#

.PHONY: test

.PHONY: tparse/install
## install tparse
tparse/install: \
$(GOPATH)bin/tparse

$(GOPATH)bin/tparse:
$(call go-install, github.com/mfridman/tparse)

.PHONY: gotestfmt/install
## install gotestfmt
gotestfmt/install: \
$(GOPATH)bin/gotestfmt

$(GOPATH)bin/gotestfmt:
$(call go-install, github.com/haveyoudebuggedit/gotestfmt/v2/cmd/gotestfmt)

.PHONY: gotests/install
## install gotests
gotests/install: \
$(GOPATH)bin/gotests

$(GOPATH)bin/gotests:
$(call go-install, github.com/cweill/gotests/gotests)

## run tests for cmd, internal, pkg
test:
go test -shuffle=on -race -mod=readonly -cover -timeout=30m ./cmd/... ./internal/... ./pkg/...

.PHONY: test/tparse
## run tests for cmd, internal, pkg and show table
test/tparse:
go test -shuffle=on -race -mod=readonly -json -cover -timeout=30m ./cmd/... ./internal/... ./pkg/... | tparse -notests

.PHONY: test/cmd
## run tests for cmd
test/cmd:
go test -shuffle=on -race -mod=readonly -cover ./cmd/...
test/tparse: \
tparse/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover -timeout=30m ./cmd/... ./internal/... ./pkg/... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| tparse -pass -notests

.PHONY: test/cmd/tparse
## run tests for cmd and show table
test/cmd/tparse:
go test -shuffle=on -race -mod=readonly -json -cover ./cmd/... | tparse -pass -notests

.PHONY: test/internal
## run tests for internal
test/internal:
go test -shuffle=on -race -mod=readonly -cover ./internal/...
test/cmd/tparse: \
tparse/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover -timeout=30m ./cmd/... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| tparse -pass -notests

.PHONY: test/internal/tparse
## run tests for internal and show table
test/internal/tparse:
go test -shuffle=on -race -mod=readonly -json -cover ./internal/... | tparse -pass -notests
test/internal/tparse: \
tparse/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover -timeout=30m ./internal/... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| tparse -pass -notests

.PHONY: test/pkg/tparse
## run tests for pkg and who table
test/pkg/tparse: \
tparse/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover -timeout=30m ./pkg/... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| tparse -pass -notests

.PHONY: test/hack/tparse
## run tests for hack and show table
test/hack/tparse: \
tparse/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover \
./hack/gorules/... \
./hack/helm/... \
./hack/license/... \
./hack/tools/... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| tparse -pass -notests

.PHONY: test/all/tparse
## run tests for all Go codes and show table
test/all/tparse: \
tparse/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover -timeout=30m ./... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| tparse -pass -notests

.PHONY: test/gotestfmt
## run tests for cmd, internal, pkg and show table
test/gotestfmt: \
gotestfmt/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover -timeout=30m ./cmd/... ./internal/... ./pkg/... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| gotestfmt -showteststatus

.PHONY: test/cmd/gotestfmt
## run tests for cmd and show table
test/cmd/gotestfmt: \
gotestfmt/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover -timeout=30m ./cmd/... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| gotestfmt -showteststatus

.PHONY: test/internal/gotestfmt
## run tests for internal and show table
test/internal/gotestfmt: \
gotestfmt/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover -timeout=30m ./internal/... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| gotestfmt -showteststatus

.PHONY: test/pkg/gotestfmt
## run tests for pkg and who table
test/pkg/gotestfmt: \
gotestfmt/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover -timeout=30m ./pkg/... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| gotestfmt -showteststatus

.PHONY: test/hack/gotestfmt
## run tests for hack and show table
test/hack/gotestfmt: \
gotestfmt/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover \
./hack/gorules/... \
./hack/helm/... \
./hack/license/... \
./hack/tools/... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| gotestfmt -showteststatus

.PHONY: test/all/gotestfmt
## run tests for all Go codes and show table
test/all/gotestfmt: \
gotestfmt/install
set -euo pipefail
rm -rf "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json"
go test -shuffle=on -race -mod=readonly -json -cover -timeout=30m ./... \
| tee "$(TEST_RESULT_DIR)/`echo $@ | sed -e 's%/%-%g'`-result.json" \
| gotestfmt -showteststatus

.PHONY: test/pkg
## run tests for pkg
test/pkg:
go test -shuffle=on -race -mod=readonly -cover ./pkg/...

.PHONY: test/pkg/tparse
## run tests for pkg and who table
test/pkg/tparse:
go test -shuffle=on -race -mod=readonly -json -cover ./pkg/... | tparse -pass -notests
.PHONY: test/internal
## run tests for internal
test/internal:
go test -shuffle=on -race -mod=readonly -cover ./internal/...

.PHONY: test/cmd
## run tests for cmd
test/cmd:
go test -shuffle=on -race -mod=readonly -cover ./cmd/...

.PHONY: test/hack
## run tests for hack
Expand All @@ -63,42 +196,17 @@ test/hack:
./hack/license/...\
./hack/tools/...

.PHONY: test/hack/tparse
## run tests for hack and show table
test/hack/tparse:
go test -shuffle=on -race -mod=readonly -json -cover
./hack/gorules/... \
./hack/helm/... \
./hack/license/... \
./hack/tools/... \
| tparse -pass -notests

.PHONY: test/all
## run tests for all Go codes
test/all:
go test -shuffle=on -race -mod=readonly -cover ./...

.PHONY: test/all/tparse
## run tests for all Go codes and show table
test/all/tparse:
go test -shuffle=on -race -mod=readonly -json -cover ./... | tparse -notests

.PHONY: coverage
## calculate coverages
coverage:
go test -shuffle=on -race -mod=readonly -v -race -covermode=atomic -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html

.PHONY: tparse/install
## install tparse
tparse/install:
$(call go-install, github.com/mfridman/tparse)

.PHONY: gotests/install
## install gotests
gotests/install:
$(call go-install, github.com/cweill/gotests/gotests)

.PHONY: gotests/gen
## generate missing go test files
gotests/gen: \
Expand Down
1 change: 1 addition & 0 deletions dockers/ci/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ RUN make ngt/install \
&& make kubelinter/install \
&& make yq/install \
&& make tparse/install \
&& make gotestfmt/install \
&& make golangci-lint/install \
&& make reviewdog/install \
&& make kubectl/install \
Expand Down