From 18191b28aa967ae78e658f9e6aa7fad6c0585bd6 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Mon, 9 Sep 2019 03:04:53 +0200 Subject: [PATCH] Makefile improvements Make watcher more robust by appending || exit 0 Revert back to GOTEST variable to allow use of other go-test utilities, like rakyll/gotest --- Makefile | 19 +++++++++++-------- tests/README.md | 31 ++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 593567b60..ad9b35aeb 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ GO = go GOGET = $(GO) get -u -GOTEST = go test +GOTEST ?= go test BASEPKGS = system compose messaging IMAGES = corteza-server-system corteza-server-compose corteza-server-messaging corteza-server @@ -12,8 +12,11 @@ IMAGES = corteza-server-system corteza-server-compose corteza-server-messaging WATCH_DELAY ?= 1s # Run go test cmd with flags, eg: -# $> TEST_FLAGS=-v make test.integration -TEST_FLAGS ?= +# $> TEST_FLAGS="-v" make test.integration +# $> TEST_FLAGS="-v -run SpecialTest" make test.integration +TEST_FLAGS ?= + +TEST_INTEGRATION_COVER_PROFILE_OUT ?= .integration.cover.out ######################################################################################################################## # Tool bins @@ -77,12 +80,12 @@ mailhog.up: watch.test.integration: $(NODEMON) # Development helper - watches for file # changes & reruns integration tests - $(WATCHER) "make test.integration" + $(WATCHER) "make test.integration || exit 0" watch.test.integration.coverage: $(NODEMON) # Development helper - watches for file # changes & reruns integration tests - $(WATCHER) "make test.integration.coverage" + $(WATCHER) "make test.integration.coverage || exit 0" ######################################################################################################################## # QA @@ -90,16 +93,16 @@ watch.test.integration.coverage: $(NODEMON) ## refactored test.integration: - $(GO) test $(TEST_FLAGS) ./tests/... + $(GOTEST) $(TEST_FLAGS) ./tests/... test.integration.coverage: - $(GO) test $(TEST_FLAGS) -covermode=count -coverprofile=.integration.cover.out -coverpkg=./... ./tests/... + $(GOTEST) $(TEST_FLAGS) -covermode=count -coverprofile=$(TEST_INTEGRATION_COVER_PROFILE_OUT) -coverpkg=./... ./tests/... ## old: test: # Run basic unit tests - $(GO) test ./pkg/... ./internal/... ./compose/... ./messaging/... ./system/... + $(GOTEST) ./pkg/... ./internal/... ./compose/... ./messaging/... ./system/... test-coverage: overalls -project=github.com/cortezaproject/corteza-server -covermode=count -- -coverpkg=./... --tags=integration -p 1 diff --git a/tests/README.md b/tests/README.md index dce4cae0e..32727a886 100644 --- a/tests/README.md +++ b/tests/README.md @@ -19,18 +19,17 @@ What, how and why we test: Are we handling access control and log events (audit log) properly? All services and data should be protected to prevent unwanted access - and modifications + and modifications. - Scenarios: Are complex scenarios executed as designed (e.g. is password recovery email sent and can link from the email be used) - + - Integration with external services All external services (with exception to database) are mocked but we do test if communication to these services take place and if - - Database schema & data migrations @@ -41,3 +40,29 @@ What, how and why we test: that occurred while testing +# Running tests + +To run integration tests once: +```shell script +make test.integration +``` + +For development, you can watch file-system changes (with `nodemon` utility) and rerun-tests everytime: +```shell script +make watch.test.integration +``` + +## Environmental variables you can sue: + +### Change test utility wih `GOTEST` + +If you want some colors in your CLI, you can use [rakyll/gotest](https://github.com/rakyll/gotest). + +```shell script +GOTEST=$GOPATH/bin/gotest make watch.test.integration +``` + +### Finetune test execution with `TEST_FLAGS` +Examples: + - `TEST_FLAGS="-v" make ....` + - `TEST_FLAGS="-v -run testName" make ....`