-
Notifications
You must be signed in to change notification settings - Fork 5
Fixes #21: merge test coverage with e2e tests in CI #22
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
|
|
@@ -34,6 +35,15 @@ coverage: | |
| go test -coverprofile=coverage.out -coverpkg=./... ./... | ||
| go tool cover -func coverage.out | ||
|
|
||
| # get test coverage-ci | ||
| .PHONY: coverage-ci | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest two options:
# 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
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.htmlWhich 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 | ||
|
|
||
There was a problem hiding this comment.
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