Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Run unit tests with race detector
if: runner.os != 'Windows'
run: |
go test -race -v -coverprofile=coverage.out -coverpkg=./... ./...
make coverage-ci TEST_FLAGS="-race -v"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's inline this so that workflow won't depend on Makefile

mkdir coverage
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
MAKEFLAGS += --always-make
TEST_FLAGS ?=

all: generate fmt lint test test-examples tidy

Expand Down Expand Up @@ -34,6 +35,15 @@ coverage:
go test -coverprofile=coverage.out -coverpkg=./... ./...
go tool cover -func coverage.out

# get test coverage-ci
.PHONY: coverage-ci

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.PHONY isn't needed here because we have MAKEFLAGS += --always-make

coverage-ci:
go test $(TEST_FLAGS) -coverprofile=coverage.unit.out -coverpkg=./... ./...
go test $(TEST_FLAGS) -tags e2e -coverprofile=coverage.e2e.out -coverpkg=./... ./... || true
go run github.com/dlespiau/covertool@latest merge -o coverage.out coverage.unit.out coverage.e2e.out

@metafates metafates Jun 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, I think we should avoid relying on third-party tools.

I think we can simplify this a bit.

Overall, it should look like this:

  1. go test ./... - run unit tests
  2. go test -tags e2e -count 1 ./examples_test.go - run e2e tests
  3. go test -tags example -coverprofile coverage.out -coverpkg ./... ./... || true - run both unit tests and examples (which are invoked from e2e).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest two options:

  1. Simple, but it requires running unit tests twice (first without coverage, then again during the general test run)
# Run unit tests separately to catch errors
go test -race -v ./...

# Run all tests together for coverage (ignoring failures)
go test -race -v -tags e2e -coverprofile=coverage.out -coverpkg=./... ./... || true

go tool cover -func=coverage.out
go tool cover -html=coverage.out -o coverage/coverage.html
  1. Using go tool covdata. This is the official Go tool introduced in v1.20, designed exactly for this use case.
mkdir -p coverage/unit coverage/e2e coverage/merged

# Run unit tests and save raw coverage data to coverage/unit
go test -race -v -coverpkg=./... ./... -test.gocoverdir=coverage/unit

# Run e2e tests and save raw coverage data to coverage/e2e (ignoring failures)
go test -race -v -tags e2e -coverpkg=./... ./... -test.gocoverdir=coverage/e2e || true

# Merge data from both directories into coverage/merged
go tool covdata merge -i=coverage/unit,coverage/e2e -o=coverage/merged

# Convert merged data to text format (coverage.out)
go tool covdata textfmt -i=coverage/merged -o=coverage.out

# Generate a report to the console
go tool cover -func=coverage.out

# Save the report to text and HTML files
go tool cover -func=coverage.out -o coverage/coverage.out
go tool cover -html=coverage.out -o coverage/coverage.html

Which approach do you think is more suitable?

go tool cover -func=coverage.out
rm -f coverage.unit.out coverage.e2e.out

# visualize test coverage
coverage-html: coverage
go tool cover -html coverage.out
Expand Down