From f07c409dcd586dc04ff9c449962e42c6d492fadd Mon Sep 17 00:00:00 2001 From: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com> Date: Thu, 20 Jul 2023 09:15:47 +0700 Subject: [PATCH] Update go test command (#4514) * Update go test command Signed-off-by: khanhtc1202 * Update makefile and github action command Signed-off-by: khanhtc1202 * Revert gitignore Signed-off-by: khanhtc1202 --------- Signed-off-by: khanhtc1202 Signed-off-by: hungran <26101787+hungran@users.noreply.github.com> --- .github/workflows/test.yaml | 2 +- Makefile | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c6137ad21b..15aabbe4c6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -24,7 +24,7 @@ jobs: go-version: ${{ env.GO_VERSION }} cache: true - name: Run unit tests - run: make test/go + run: make test/go COVERAGE=true - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 env: diff --git a/Makefile b/Makefile index 8637c3772a..b027b328df 100644 --- a/Makefile +++ b/Makefile @@ -73,8 +73,17 @@ push/chart: test: test/go test/web .PHONY: test/go +test/go: COVERAGE ?= false +test/go: COVERAGE_OPTS ?= -covermode=atomic +test/go: COVERAGE_OUTPUT ?= coverage.out test/go: - go test ./pkg/... ./cmd/... +ifeq ($(COVERAGE), true) + go test -failfast -race $(COVERAGE_OPTS) -coverprofile=$(COVERAGE_OUTPUT).tmp ./pkg/... ./cmd/... + cat $(COVERAGE_OUTPUT).tmp | grep -v ".pb.go\|.pb.validate.go" > $(COVERAGE_OUTPUT) + rm -rf $(COVERAGE_OUTPUT).tmp +else + go test -failfast -race ./pkg/... ./cmd/... +endif .PHONY: test/web test/web: