Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit d782a4f

Browse files
committed
Add coverage target in Makefile for coverage reporting
Signed-off-by: Joffrey F <[email protected]>
1 parent 1dde7ad commit d782a4f

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.tar.gz
22
*.dockerapp
33
_build/
4+
codecoverage/*.out
45
!examples/simple/*.dockerapp

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ unit-test:
8383
clean:
8484
rm -Rf ./_build docker-app-*.tar.gz
8585

86+
coverage-bin:
87+
$(GO_TEST) -coverpkg="./..." -c -tags testrunmain -o _build/$(BIN_NAME).cov
88+
89+
coverage: coverage-bin
90+
DOCKERAPP_BINARY=../codecoverage/coverage-bin $(GO_TEST) -v ./e2e
91+
$(GO_TEST) -cover -test.coverprofile=codecoverage/unit.out $(shell go list ./... | grep -vE '/vendor/|/e2e')
92+
gocovmerge codecoverage/*.out > codecoverage/all.out
93+
go tool cover -func codecoverage/all.out
94+
8695
##########################
8796
# Continuous Integration #
8897
##########################

codecoverage/coverage-bin

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# This script is a proxy that injects the required test flags and strips out test output
4+
# It allows us to use a coverage-enabled binary for e2e tests
5+
6+
../_build/docker-app.cov $* -test.v -test.coverprofile=../codecoverage/e2e.out | \
7+
grep -vE '^PASS$' | grep -vE '^coverage: [0-9]+\.[0-9]+% of statements in .+$' | grep -v '^=== RUN TestRunMain$'

main_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build testrunmain
2+
3+
package main
4+
5+
import "testing"
6+
7+
func TestRunMain(t *testing.T) {
8+
main()
9+
}

0 commit comments

Comments
 (0)