From 051f3884e1fcd5df3d07a7199e9df40bb29702d0 Mon Sep 17 00:00:00 2001 From: Andrey Dyachkov Date: Sat, 11 Aug 2018 21:12:24 +0200 Subject: [PATCH] Bring more clarity on how to run unit tests (#449) * The commit brings more clarity on how to run unut tests. The commit chages behaivour of `make test-unit` by adding sourcing of env vars. Documentation is updated to provide more clarity on how to run unit tests. * changed list of commands to run before unit tests * moved env vars to .env * removed dduplicated env var * returned conventional file name in script * link to DEVELOPMENT.md * fixed typo * moved env var export to script * removed export of tmp folder --- CONTRIBUTING.md | 2 +- DEVELOPMENT.md | 21 +++++++++++++++++++++ cmd/proxy/.env | 2 ++ scripts/test_unit.sh | 4 +++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ca863cea..665f8701 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,7 +12,7 @@ Run `make setup-dev-env` to install local developer tools and run necessary services, such as mongodb, for the end-to-end tests. ## Unit Tests -Run `make test-unit` to run the unit tests. +For further details see [DEVELOPMENT.md](DEVELOPMENT.md#L84) ## End-to-End Tests End-to-End tests (e2e) are tests from the user perspective that validate that diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 6a4d82b5..d08bfcc8 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -80,3 +80,24 @@ Starting application at 127.0.0.1:3000 And you'll be up and running. As you edit and save code, the `buffalo dev` command will notice and automatically re-compile and restart the server. + +# Run unit tests + +In order to run unit tests, services they depend on must be running first: + +```console +make alldeps +``` + +and database created: + +```console +buffalo db create +buffalo db migrate up +``` + +then you can run the unit tests: + +```console +make test-unit +``` diff --git a/cmd/proxy/.env b/cmd/proxy/.env index 8e7b14f7..22ebef05 100644 --- a/cmd/proxy/.env +++ b/cmd/proxy/.env @@ -1 +1,3 @@ ATHENS_MONGO_STORAGE_URL=mongodb://127.0.0.1:27017 +GO_ENV=test_postgres +POP_PATH=$PWD/cmd/proxy diff --git a/scripts/test_unit.sh b/scripts/test_unit.sh index 6f9a21cd..e9c86e72 100755 --- a/scripts/test_unit.sh +++ b/scripts/test_unit.sh @@ -1,7 +1,9 @@ #!/bin/bash # test_unit.sh + +source cmd/proxy/.env + # Run the unit tests with the race detector and code coverage enabled set -xeuo pipefail - go test -race -coverprofile cover.out -covermode atomic ./...