From ebd3ad8842c1d1a27c0573d48a9861d73f148407 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 30 Apr 2021 18:58:26 +0300 Subject: [PATCH 1/5] Makefile: add test and cover targets --- .gitignore | 3 +++ Makefile | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 43e1681..2726d2d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ testfile .neofs-cli.yml .cache + +coverage.txt +coverage.html diff --git a/Makefile b/Makefile index 77c7436..1797e7a 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ BINDIR = bin DIRS = $(BINDIR) BINS = "$(BINDIR)/neofs-http-gw" -.PHONY: help all dep clean fmts fmt imports test lint docker/lint +.PHONY: help all dep clean fmts fmt imports test cover lint docker/lint # Make all binaries all: $(BINS) @@ -43,6 +43,15 @@ dep: GO111MODULE=on \ go mod tidy -v && echo OK +# Run tests +test: + @go test ./... -cover + +# Run tests with race detection and produce coverage output +cover: + @go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic + @go tool cover -html=coverage.txt -o coverage.html + # Run all code formatters fmts: fmt imports From 7ba5aed9cabebd767df03db67b9d9ea0c17f2fd0 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 30 Apr 2021 19:02:30 +0300 Subject: [PATCH 2/5] tokens: fix tests Broken by afbb9d51f16413bc2e12aff6e8cb5133329f5c22 which changed some strings. --- tokens/bearer-token_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tokens/bearer-token_test.go b/tokens/bearer-token_test.go index c6ee703..f038014 100644 --- a/tokens/bearer-token_test.go +++ b/tokens/bearer-token_test.go @@ -82,17 +82,17 @@ func Test_fetchBearerToken(t *testing.T) { }{ {name: "empty"}, - {name: "bad base64 header", header: "WRONG BASE64", error: "could not fetch marshaled from base64"}, - {name: "bad base64 cookie", cookie: "WRONG BASE64", error: "could not fetch marshaled from base64"}, + {name: "bad base64 header", header: "WRONG BASE64", error: "can't base64-decode bearer token"}, + {name: "bad base64 cookie", cookie: "WRONG BASE64", error: "can't base64-decode bearer token"}, - {name: "header token unmarshal error", header: "dGVzdAo=", error: "could not unmarshal bearer token"}, - {name: "cookie token unmarshal error", cookie: "dGVzdAo=", error: "could not unmarshal bearer token"}, + {name: "header token unmarshal error", header: "dGVzdAo=", error: "can't unmarshal bearer token"}, + {name: "cookie token unmarshal error", cookie: "dGVzdAo=", error: "can't unmarshal bearer token"}, { name: "bad header and cookie", header: "WRONG BASE64", cookie: "dGVzdAo=", - error: "could not unmarshal bearer token", + error: "can't unmarshal bearer token", }, { From f05a6eda7da8aa251cfd1494adf2a670975e639f Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 30 Apr 2021 19:08:57 +0300 Subject: [PATCH 3/5] workflows: add testing workflow --- .github/workflows/tests.yml | 75 +++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..e6ac620 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,75 @@ +name: Tests + +on: + pull_request: + branches: + - master + types: [opened, synchronize] + paths-ignore: + - '**/*.md' + workflow_dispatch: + +jobs: + cover: + name: Coverage + runs-on: ubuntu-18.04 + + env: + CGO_ENABLED: 0 + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Restore Go modules from cache + uses: actions/cache@v2 + with: + path: /home/runner/go/pkg/mod + key: deps-${{ hashFiles('go.sum') }} + + - name: Update Go modules + run: make dep + + - name: Test and write coverage profile + run: make cover + + - name: Upload coverage results to Codecov + uses: codecov/codecov-action@v1 + with: + fail_ci_if_error: false + path_to_write_report: ./coverage.txt + verbose: true + + tests: + name: Tests + runs-on: ubuntu-18.04 + strategy: + matrix: + go_versions: [ '1.16' ] + fail-fast: false + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '${{ matrix.go_versions }}' + + - name: Restore Go modules from cache + uses: actions/cache@v2 + with: + path: /home/runner/go/pkg/mod + key: deps-${{ hashFiles('go.sum') }} + + - name: Update Go modules + run: make dep + + - name: Run tests + run: make test From 25d273f88ee1b2db43bfa315edd211fb33db77f9 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 30 Apr 2021 19:09:41 +0300 Subject: [PATCH 4/5] workflows: move linter to tests from builds --- .github/workflows/builds.yml | 13 +------------ .github/workflows/tests.yml | 11 +++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 3d48f16..078d286 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -1,4 +1,4 @@ -name: Builds and lints +name: Builds on: pull_request: @@ -10,17 +10,6 @@ on: workflow_dispatch: jobs: - lint: - name: Lint - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: latest - build_cli: name: Build CLI runs-on: ubuntu-18.04 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e6ac620..529f986 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,6 +10,17 @@ on: workflow_dispatch: jobs: + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: latest + cover: name: Coverage runs-on: ubuntu-18.04 From d5cdcb29c31010ff2952693490cff4dcf5f9553a Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 30 Apr 2021 19:14:12 +0300 Subject: [PATCH 5/5] workflows: use Ubuntu 20.04 instead of 18.04 18.04 is a bit old. --- .github/workflows/builds.yml | 4 ++-- .github/workflows/publish_to_dockerhub.yml | 2 +- .github/workflows/tests.yml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 078d286..9532af8 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -12,7 +12,7 @@ on: jobs: build_cli: name: Build CLI - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 @@ -45,7 +45,7 @@ jobs: build_image: needs: build_cli name: Build Docker image - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/publish_to_dockerhub.yml b/.github/workflows/publish_to_dockerhub.yml index c44d409..4c6908d 100644 --- a/.github/workflows/publish_to_dockerhub.yml +++ b/.github/workflows/publish_to_dockerhub.yml @@ -27,7 +27,7 @@ on: jobs: publish: name: Publish image to DockerHub - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - name: Checkout (manual run) if: ${{ github.event_name == 'workflow_dispatch' }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 529f986..09356a2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,7 +23,7 @@ jobs: cover: name: Coverage - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 env: CGO_ENABLED: 0 @@ -58,7 +58,7 @@ jobs: tests: name: Tests - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: go_versions: [ '1.16' ]