Added unit-tests in Makefile
* This commit will add unit-tests and coverprofile for the tests. * Adds ability to run make unit-tests command. * This has been referenced from the Airshipctl project. Change-Id: Ida6bfe64b7fc166072ae6357940d283fa3d60349
This commit is contained in:
parent
3fefc40632
commit
99235e2aec
23
Makefile
23
Makefile
@ -34,6 +34,13 @@ COVERAGE_OUTPUT := coverage.out
|
||||
|
||||
TESTFLAGS ?= -count=1
|
||||
|
||||
# go options
|
||||
PKG ?= ./...
|
||||
TESTS ?= .
|
||||
COVER_FLAGS ?=
|
||||
COVER_PROFILE ?= cover.out
|
||||
COVER_EXCLUDE ?= (zz_generated)
|
||||
|
||||
# Override the value of the version variable in main.go
|
||||
LD_FLAGS= '-X opendev.org/airship/airshipui/internal/commands.version=$(GIT_VERSION)'
|
||||
GO_FLAGS := -ldflags=$(LD_FLAGS)
|
||||
@ -82,14 +89,20 @@ install-npm-modules: $(NPX)
|
||||
cd $(WEBDIR) && (PATH="$(PATH):$(JSLINTER_BIN)"; $(NPM) install) && cd ..
|
||||
|
||||
.PHONY: test
|
||||
test: lint
|
||||
test: cover
|
||||
test: check-copyright
|
||||
test:
|
||||
go test $(RECURSIVE_DIRS) -v $(TESTFLAGS)
|
||||
|
||||
.PHONY: unit-tests
|
||||
unit-tests:
|
||||
@echo "Performing unit test step..."
|
||||
@go test -run $(TESTS) $(PKG) $(TESTFLAGS) $(COVER_FLAGS)
|
||||
@echo "All unit tests passed"
|
||||
|
||||
.PHONY: cover
|
||||
cover: TESTFLAGS += -coverprofile=$(COVERAGE_OUTPUT)
|
||||
cover: test
|
||||
go tool cover -html=$(COVERAGE_OUTPUT)
|
||||
cover: TESTFLAGS = -covermode=atomic -coverprofile=fullcover.out
|
||||
cover: unit-tests
|
||||
@grep -vE "$(COVER_EXCLUDE)" fullcover.out > $(COVER_PROFILE)
|
||||
|
||||
.PHONY: images
|
||||
images: docker-image
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
---
|
||||
- hosts: all
|
||||
name: Run tests
|
||||
name: Run unit-tests
|
||||
tasks:
|
||||
- name: make docker-image-unit-tests
|
||||
make:
|
||||
|
Loading…
Reference in New Issue
Block a user