From d8cd184107c1be05c5f71cfd6bed87ebf8e49291 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Sun, 11 Aug 2019 22:29:21 +0200 Subject: [PATCH] feat: enable codecov --- .circleci/config.yml | 11 +++++++---- .gitignore | 2 ++ Makefile | 10 +++++++++- pkg/randstring/randstring_test.go | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 pkg/randstring/randstring_test.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 271874412..d2978683a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,6 +5,8 @@ orbs: dl: moul/dl@1.7.0 # https://github.com/moul/dl/blob/master/.circleci/config.yml retry: moul/retry@0.6.0 # https://github.com/moul/retry/blob/master/.circleci/config.yml tools: gotest/tools@0.0.9 + docker: circleci/docker@0.5.13 + codecov: codecov/codecov@1.0.5 executors: golang: @@ -36,11 +38,10 @@ jobs: # FIXME: save cache # build and unit test the project - test: + go_test: executor: golang steps: - checkout - # FIXME: restore cache - run: go clean -modcache - retry/install - tools/mod-download @@ -50,7 +51,9 @@ jobs: # FIXME: setup coverage - moul/install_golangci-lint - run: . ~/.profile && retry -m 3 make lint - # FIXME: save cache + - codecov/upload: + file: coverage.txt + flags: go_test # FIXME: store_test_results docker_integration: @@ -69,6 +72,6 @@ jobs: workflows: main: jobs: - - test + - go_test - docker_build - docker_integration diff --git a/.gitignore b/.gitignore index afab18645..315fbebaa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +coverage.txt + .env node_modules diff --git a/Makefile b/Makefile index caec3f545..e6ee3ab58 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,15 @@ $(PWCTL_OUT_FILES): $(PWCTL_SOURCES) .PHONY: test test: .proto.generated - go test -mod=readonly -v ./... + echo "" > /tmp/coverage.txt + set -e; for dir in `find . -type f -name "go.mod" | sed -r 's@/[^/]+$$@@' | sort | uniq`; do (set -xe; \ + cd $$dir; \ + go test -v -mod=readonly -cover -coverprofile=/tmp/profile.out -covermode=atomic -race ./...; \ + if [ -f /tmp/profile.out ]; then \ + cat /tmp/profile.out >> /tmp/coverage.txt; \ + rm -f /tmp/profile.out; \ + fi); done + mv /tmp/coverage.txt . %.pb.go: %.proto protoc \ diff --git a/pkg/randstring/randstring_test.go b/pkg/randstring/randstring_test.go new file mode 100644 index 000000000..23d9af116 --- /dev/null +++ b/pkg/randstring/randstring_test.go @@ -0,0 +1,15 @@ +package randstring + +import ( + "fmt" + "math/rand" +) + +func ExampleRandString() { + rand.Seed(42) + fmt.Println(RandString(10)) + fmt.Println(RandString(42)) + // output: + // CBzlgwF4Xt + // dzFemEMgBqNznwB199sND0jQ6KJ402CKj1s8Oquw5O +}