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

Commit 6cb629a

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

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
@@ -84,6 +84,15 @@ unit-test:
8484
clean:
8585
rm -Rf ./_build docker-app-*.tar.gz
8686

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

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)