From 6690f37426f008e5c561ec663e86c15b18e63f95 Mon Sep 17 00:00:00 2001 From: shivdudhani Date: Fri, 7 Jun 2019 11:50:12 -0700 Subject: [PATCH] initial targets for unit test and code coverage --- Makefile | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c7f82bfdf3..ec16c38f4d 100644 --- a/Makefile +++ b/Makefile @@ -55,4 +55,34 @@ docker-tag-repo: docker-push: @docker push $(REPO):$(IMAGE_TAG) - @docker push $(REPO):latest \ No newline at end of file + @docker push $(REPO):latest + +## Testing & Code-Coverage + +## variables +BIN_DIR := $(GOPATH)/bin +GO_ACC := $(BIN_DIR)/go-acc +CODE_COVERAGE_FILE:= coverage +CODE_COVERAGE_FILE_TXT := $(CODE_COVERAGE_FILE).txt +CODE_COVERAGE_FILE_HTML := $(CODE_COVERAGE_FILE).html + +## targets +$(GO_ACC): + @echo " downloading testing tools" + go get -v github.com/ory/go-acc + $(eval export PATH=$(GO_ACC):$(PATH)) +# go test provides code coverage per packages only. +# go-acc merges the result for pks so that it be used by +# go tool cover for reporting + +# go get downloads and installs the binary +# we temporarily add the GO_ACC to the path +test-all: $(GO_ACC) + @echo " running unit tests" + go-acc ./... -o $(CODE_COVERAGE_FILE_TXT) + +code-cov-report: $(CODE_COVERAGE_FILE_TXT) +# transform to html format + @echo " generating code coverage report" + go tool cover -html=coverage.txt + if [ -a $(CODE_COVERAGE_FILE_HTML) ]; then open $(CODE_COVERAGE_FILE_HTML); fi; \ No newline at end of file