From e735cb363365524d6b949fc96e2f8bcf274322f5 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Mon, 14 Oct 2024 15:11:11 +0800 Subject: [PATCH] feat: simplify mock handling mockgen generated mocks are now expected to be: * in the same directory as the _test.go files * suffixed _mock_test.go, so they are handled correctly by the go tooling (ignored during build, coverage calculation etc.) * in the same package as the _test.go files Example: mockgen -source=foo.go -package=foo_test -destination=foo_mock_test.go -write_generate_directive --- .github/workflows/coverage.yaml | 4 +--- .gitignore | 1 - Makefile | 3 +-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 890d2b4..9459885 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -16,9 +16,7 @@ jobs: go-version: stable - name: Calculate coverage run: | - go test -v -covermode=atomic -coverprofile=cover.out.raw -coverpkg=./... ./... - # remove generated code from coverage calculation - grep -Ev 'internal/mock|_enumer.go' cover.out.raw > cover.out + go test -v -covermode=atomic -coverprofile=cover.out -coverpkg=./... ./... - name: Generage coverage badge uses: vladopajic/go-test-coverage@c7fe52e0f48e0fbed8c1812824c5346218443c70 # v2.10.2 with: diff --git a/.gitignore b/.gitignore index 7e275b7..6ee2014 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ /dist /cover.out -/cover.out.raw /sbom.spdx.json diff --git a/Makefile b/Makefile index 4655e5c..aacc1ca 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,5 @@ fuzz: mod-tidy generate .PHONY: cover cover: mod-tidy generate - go test -v -covermode=atomic -coverprofile=cover.out.raw -coverpkg=./... ./... - grep -Ev 'internal/mock|_enumer.go' cover.out.raw > cover.out + go test -v -covermode=atomic -coverprofile=cover.out -coverpkg=./... ./... go tool cover -html=cover.out