Skip to content

Commit ea8ae55

Browse files
committed
makefile: Add a make target to generate test coverage report
1 parent b62341b commit ea8ae55

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ bin
1111

1212
# Output of the go coverage tool, specifically when used with LiteIDE
1313
*.out
14+
coverage.*
1415

1516
# Ansible
1617
*.retry

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,21 @@ help: ## Display this help
136136
.PHONY: test
137137
test: generate lint go-test ## Run generate lint and tests
138138

139-
go-test: export TEST_ASSET_KUBECTL = $(KUBECTL)
140-
go-test: export TEST_ASSET_KUBE_APISERVER = $(KUBE_APISERVER)
141-
go-test: export TEST_ASSET_ETCD = $(ETCD)
139+
envs-test:
140+
export TEST_ASSET_KUBECTL = $(KUBECTL)
141+
export TEST_ASSET_KUBE_APISERVER = $(KUBE_APISERVER)
142+
export TEST_ASSET_ETCD = $(ETCD)
142143

143144
.PHONY: go-test
144-
go-test: $(KUBECTL) $(KUBE_APISERVER) $(ETCD) ## Run go tests
145+
go-test: envs-test $(KUBECTL) $(KUBE_APISERVER) $(ETCD) ## Run go tests
146+
echo $(TEST_ASSET_KUBECTL)
145147
go test ./...
146148

149+
.PHONY: test-cover
150+
test-cover: envs-test $(KUBECTL) $(KUBE_APISERVER) $(ETCD) ## Run tests with code coverage and code generate reports
151+
go test -v -coverprofile=coverage.out ./...
152+
go tool cover -func=coverage.out -o coverage.txt
153+
go tool cover -html=coverage.out -o coverage.html
147154

148155
.PHONY: test-integration
149156
test-integration: ## Run integration tests

0 commit comments

Comments
 (0)