Skip to content
This repository has been archived by the owner on May 6, 2021. It is now read-only.

Commit

Permalink
Add Coverage (#5)
Browse files Browse the repository at this point in the history
* Add coverage of the packages

* Add coverage to ci and codecov

* build and use goverage from vendor dir

* no colour when running codecov
  • Loading branch information
chmouel authored Oct 3, 2018
1 parent 3172ba7 commit a7de2a1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .cico/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function deploy() {
make image

TAG=$(echo $GIT_COMMIT | cut -c1-${DEVSHIFT_TAG_LEN})

if [ "$TARGET" = "rhel" ]; then
tag_push ${REGISTRY}/openshiftio/rhel-fabric8-services-fabric8-build-service $TAG
tag_push ${REGISTRY}/openshiftio/rhel-fabric8-services-fabric8-build-service latest
Expand All @@ -72,4 +71,8 @@ function dotest() {

make analyze-go-code
make test-unit
make coverage

# Upload to codecov
bash <(curl -s https://codecov.io/bash) -K -X search -f tmp/coverage.out -t 533b56c6-9fec-4ff2-9756-6aea46d46f2b
}
9 changes: 8 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ required = [
"github.com/davecgh/go-spew/spew",
"github.com/golang/lint/golint",
"github.com/fzipp/gocyclo",
"github.com/haya14busa/goverage",
"github.com/pilu/fresh", # used to rebuild if source changed while running
]

Expand Down
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SOURCES := $(shell find $(SOURCE_DIR) -path $(SOURCE_DIR)/vendor -prune -o -name
DESIGN_DIR=design
DESIGNS := $(shell find $(SOURCE_DIR)/$(DESIGN_DIR) -path $(SOURCE_DIR)/vendor -prune -o -name '*.go' -print)
ALL_PKGS_EXCLUDE_PATTERN = 'vendor\|app\|tool\/cli\|design\|client\|test'
LDFLAGS=-ldflags "-X ${PACKAGE_NAME}/app.Commit=${COMMIT} -X ${PACKAGE_NAME}/app.BuildTime=${BUILD_TIME}"

# By default reduce the amount of log output from tests
F8_LOG_LEVEL ?= error
Expand All @@ -23,8 +24,8 @@ endif

# This is a fix for a non-existing user in passwd file when running in a docker
# container and trying to clone repos of dependencies
GIT_COMMITTER_NAME ?= "user"
GIT_COMMITTER_EMAIL ?= "user@example.com"
GIT_COMMITTER_NAME ?= "Chmouel Boudjnah"
GIT_COMMITTER_EMAIL ?= "chmouel@chmouel.com"
export GIT_COMMITTER_NAME
export GIT_COMMITTER_EMAIL

Expand Down Expand Up @@ -72,12 +73,23 @@ image: clean-artifacts build-linux ## Build the docker image
--build-arg PROJECT_NAME=$(PROJECT_NAME)\
-f $(DOCKERFILE) .

# -------------------------------------------------------------------
# Unittest
# -------------------------------------------------------------------
.PHONY: test-unit
test-unit: prebuild-check generate $(SOURCES) ## Runs the unit tests and WITHOUT producing coverage files for each package.
$(call log-info,"Running test: $@")
$(eval TEST_PACKAGES:=$(shell go list ./... | grep -v $(ALL_PKGS_EXCLUDE_PATTERN)))
AUTH_DEVELOPER_MODE_ENABLED=1 AUTH_RESOURCE_UNIT_TEST=1 F8_LOG_LEVEL=$(F8_LOG_LEVEL) go test $(GO_TEST_VERBOSITY_FLAG) $(TEST_PACKAGES)

.PHONY: coverage
coverage: prebuild-check deps $(SOURCES) ## Run coverage
$(call log-info,"Running coerage: $@")
$(eval TEST_PACKAGES:=$(shell go list ./... | grep -v $(ALL_PKGS_EXCLUDE_PATTERN)))
@cd $(VENDOR_DIR)/github.com/haya14busa/goverage && go build
@./vendor/github.com/haya14busa/goverage/goverage -coverprofile=tmp/coverage.out $(TEST_PACKAGES)
@go tool cover -func tmp/coverage.out

# -------------------------------------------------------------------
# help!
# -------------------------------------------------------------------
Expand Down Expand Up @@ -249,8 +261,6 @@ dev: prebuild-check deps generate $(FRESH_BIN) ## run the server locally
# -------------------------------------------------------------------
# build the binary executable (to ship in prod)
# -------------------------------------------------------------------
LDFLAGS=-ldflags "-X ${PACKAGE_NAME}/app.Commit=${COMMIT} -X ${PACKAGE_NAME}/app.BuildTime=${BUILD_TIME}"

.PHONY: build
build: prebuild-check deps generate ## Build the server
ifeq ($(OS),Windows_NT)
Expand Down

0 comments on commit a7de2a1

Please sign in to comment.