From d53e040496a4452df4cdaf829ead3a5fe5a82c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Br=C3=B8ndum?= <34370407+brondum@users.noreply.github.com> Date: Thu, 27 Oct 2022 15:13:56 +0200 Subject: [PATCH] Fixed test, improved docs and added test step to circle pipeline (#26) --- .circleci/config.yml | 42 +++++++++++++++++++++++++++++++++++++++++- README.md | 35 +++++++++++++++++++++++------------ config/config_test.go | 4 ++-- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c21efa0..8baaecb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,6 +30,37 @@ commands: docker push gaardsholt/$CIRCLE_PROJECT_REPONAME --all-tags jobs: + test: + executor: go_image + steps: + - checkout + - run: + name: Download needed tools + command: | + go install gotest.tools/gotestsum@latest + - run: + name: go mod download + command: go mod download + - run: + name: go vet + when: always + command: go vet ./... + - run: + name: go fmt + when: always + command: | + gofmt -d -e . + if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then + exit 1 + fi + - run: + name: go test + when: always + command: | + mkdir junit + gotestsum --junitfile junit/unit-tests.xml + - store_test_results: + path: ~/project/junit build: executor: go_image steps: @@ -51,15 +82,24 @@ jobs: workflows: - build: + test_n_build: jobs: + - test: + context: gaardsholt + filters: + tags: + ignore: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ - build: context: gaardsholt + requires: + - test filters: tags: ignore: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ - build_docker: context: gaardsholt + requires: + - test filters: tags: ignore: /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/ diff --git a/README.md b/README.md index 7583598..3b1b73f 100644 --- a/README.md +++ b/README.md @@ -8,26 +8,37 @@ The main application uses port `8080`. ## Server config The following config can be set via environment variables -| Tables | Required | Default | -| ----------------------------- | :------: | --------- | -| [SERVERSALT](#SERVERSALT) | | | -| [DATABASETYPE](#DATABASETYPE) | | in-memory | -| [REDISSERVER](#REDISSERVER) | | localhost | -| [REDISPORT](#REDISPORT) | | 6379 | - - -### SERVERSALT +| Tables | Required | Default | +| ------------------------------- | :------: | --------- | +| [SERVER_SALT](#SERVER_SALT) | | | +| [DATABASE_TYPE](#DATABASE_TYPE) | | in-memory | +| [REDIS_SERVER](#REDIS_SERVER) | | localhost | +| [REDIS_PORT](#REDIS_PORT) | | 6379 | +| [SERVER_PORT](#SERVER_PORT) | | 8080 | +| [HEALTH_PORT](#HEALTH_PORT) | | 8888 | +| [LOG_LEVEL](#LOG_LEVEL) | | info | + + +### SERVER_SALT For extra security you can add your own salt when encrypting the data. -### DATABASETYPE +### DATABASE_TYPE Can either be `in-memory` or `redis`. -### REDISSERVER +### REDIS_SERVER Address to your redis server. -### REDISPORT +### REDIS_PORT Used to specify the port your redis server is using. +### SERVER_PORT +Listen port for api and ui endpoint. + +### HEALTH_PORT +Listen port for health endpoint, used mainly for liveness probes. + +### LOG_LEVEL +Used to specify loglevels, valid values are: `debug`, `info`, `warn` and `error` ## Create a new secret diff --git a/config/config_test.go b/config/config_test.go index 98ea298..07175c6 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -11,8 +11,8 @@ import ( func TestLoadConfigAsExpected(t *testing.T) { // arrange os.Clearenv() - os.Setenv("SERVERSALT", "somesalt") - os.Setenv("DATABASETYPE", "redis") + os.Setenv("SERVER_SALT", "somesalt") + os.Setenv("DATABASE_TYPE", "redis") // act LoadConfig()