Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Add control for request cookies (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Apr 3, 2021
1 parent 613f862 commit 318109d
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 41 deletions.
25 changes: 17 additions & 8 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,25 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2.3.0
uses: golangci/golangci-lint-action@v2.5.1
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.35.2
version: v1.38.0

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: ./the-only-dir-to-analyze/...
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Required: the token is used for fetching a list of releases of golangci-lint.
# The secret `GITHUB_TOKEN` is automatically created by GitHub,
# no need to create it manually.
# https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#about-the-github_token-secret
github-token: ${{ secrets.GITHUB_TOKEN }}
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
37 changes: 27 additions & 10 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ on:
pull_request:
env:
GO111MODULE: "on"
RUN_BASE_COVERAGE: "on" # Runs test for PR base in case base test coverage is missing.
jobs:
test:
strategy:
matrix:
go-version: [ 1.13.x, 1.14.x, 1.15.x ]
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand All @@ -20,22 +21,38 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Go cache
uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-cache
- name: Restore base test coverage
if: matrix.go-version == '1.16.x'
uses: actions/cache@v2
with:
path: |
unit-base.txt
# Use base sha for PR or new commit hash for master/main push in test result key.
key: ${{ runner.os }}-unit-test-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
- name: Restore vendor
uses: actions/cache@v2
- name: Checkout base code
if: matrix.go-version == '1.16.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
uses: actions/checkout@v2
with:
path: |
vendor
key: ${{ runner.os }}-go${{ matrix.go-version }}-vendor-${{ hashFiles('**/go.mod') }}
- name: Populate dependencies
ref: ${{ github.event.pull_request.base.sha }}
path: __base
- name: Run test for base code
if: matrix.go-version == '1.16.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
run: |
(test -d vendor && echo vendor found) || (go mod vendor && du -sh vendor && du -sh ~/go/pkg/mod)
cd __base
make test-unit
go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > ../unit-base.txt
- name: Test
id: test
run: |
Expand All @@ -52,7 +69,7 @@ jobs:
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
run: cp unit.txt unit-base.txt
- name: Comment Test Coverage
if: matrix.go-version == '1.15.x'
if: matrix.go-version == '1.16.x'
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -68,7 +85,7 @@ jobs:
</details>
- name: Upload code coverage
if: matrix.go-version == '1.15.x'
if: matrix.go-version == '1.16.x'
uses: codecov/codecov-action@v1
with:
file: ./unit.coverprofile
Expand Down
45 changes: 45 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
run:
tests: true

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
gocyclo:
min-complexity: 20
dupl:
threshold: 100
misspell:
locale: US
unused:
check-exported: false
unparam:
check-exported: true

linters:
enable-all: true
disable:
- lll
- maligned
- gochecknoglobals
- gomnd
- wrapcheck
- paralleltest
- forbidigo
- exhaustivestruct
- interfacer
- forcetypeassert

issues:
exclude-use-default: false
exclude-rules:
- linters:
- gomnd
- goconst
- goerr113
- noctx
- funlen
- dupl
path: "_test.go"

8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#GOLANGCI_LINT_VERSION := "v1.38.0" # Optional configuration to pinpoint golangci-lint version.

# The head of Makefile determines location of dev-go to include standard targets.
GO ?= go
export GO111MODULE = on
Expand Down Expand Up @@ -26,11 +28,9 @@ ifeq ($(DEVGO_PATH),)
endif

-include $(DEVGO_PATH)/makefiles/main.mk
-include $(DEVGO_PATH)/makefiles/test-unit.mk
-include $(DEVGO_PATH)/makefiles/lint.mk
-include $(DEVGO_PATH)/makefiles/github-actions.mk
-include $(DEVGO_PATH)/makefiles/test-unit.mk
-include $(DEVGO_PATH)/makefiles/reset-ci.mk

## Run tests
test: test-unit


6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ An additional header can be supplied. For multiple headers, call step multiple t
And I request HTTP endpoint with header "X-Foo: bar"
```

An additional cookie can be supplied. For multiple cookies, call step multiple times.

```gherkin
And I request HTTP endpoint with cookie "name: value"
```

Optionally request body can be configured. If body is a valid JSON5 payload, it will be converted to JSON before use.
Otherwise, body is used as is.

Expand Down
4 changes: 4 additions & 0 deletions _testdata/Local.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Feature: HTTP Service

And I request HTTP endpoint with header "X-Foo: bar"

And I request HTTP endpoint with cookie "c1: v1"

And I request HTTP endpoint with cookie "c2: v2"

Then I should have response with status "Bad Request"

And I should have response with body from file
Expand Down
2 changes: 1 addition & 1 deletion dev_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package httpdog_test

import _ "github.com/bool64/dev"
import _ "github.com/bool64/dev" // Include CI/Dev scripts to project.
3 changes: 1 addition & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ func ExampleNewLocal() {
Output: ioutil.Discard,
},
}
status := suite.Run()

if status != 0 {
if suite.Run() != 0 {
fmt.Println("test failed")
} else {
fmt.Println("test passed")
Expand Down
3 changes: 1 addition & 2 deletions external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ func TestRegisterExternal(t *testing.T) {
Randomize: time.Now().UTC().UnixNano(),
},
}
status := suite.Run()

if status != 0 {
if suite.Run() != 0 {
t.Fatal("unexpected error")
}

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/bool64/httpdog
go 1.13

require (
github.com/bool64/dev v0.1.15
github.com/bool64/shared v0.1.1
github.com/bool64/dev v0.1.25
github.com/bool64/shared v0.1.3
github.com/cucumber/godog v0.10.0
github.com/gofrs/uuid v3.3.0+incompatible // indirect
github.com/hashicorp/go-memdb v1.3.0 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/stretchr/testify v1.7.0
github.com/swaggest/assertjson v1.6.2
github.com/swaggest/rest v0.1.18
github.com/swaggest/assertjson v1.6.4
github.com/swaggest/rest v0.2.1
)
Loading

0 comments on commit 318109d

Please sign in to comment.