Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #34 from roman-khimov/fix-tests
Browse files Browse the repository at this point in the history
Fix tests, add workflow and makefile targets
  • Loading branch information
roman-khimov authored Apr 30, 2021
2 parents 727ec9b + d5cdcb2 commit 37fa2c6
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 21 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Builds and lints
name: Builds

on:
pull_request:
Expand All @@ -10,20 +10,9 @@ 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
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -56,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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_to_dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
86 changes: 86 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Tests

on:
pull_request:
branches:
- master
types: [opened, synchronize]
paths-ignore:
- '**/*.md'
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-20.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-20.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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ testfile
.neofs-cli.yml

.cache

coverage.txt
coverage.html
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions tokens/bearer-token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},

{
Expand Down

0 comments on commit 37fa2c6

Please sign in to comment.