Skip to content

Commit

Permalink
update (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirosassa committed Aug 25, 2022
1 parent 70c4589 commit e5d03f7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/golanglint-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.45
version: v1.49
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.19
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Test
run: go test -v ./... -coverprofile cover.out

- name: Convert coverage to lcov
uses: jandelgado/gcov2lcov-action@v1.0.8
uses: jandelgado/gcov2lcov-action@v1.0.9
if: github.ref == 'refs/heads/master'
with:
infile: cover.out
Expand Down
33 changes: 30 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
linters:
enable:
- gofmt
- goimports
enable-all: true
disable:
- golint # WARN [runner] The linter 'golint' is deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner. Replaced by revive.
- maligned # WARN [runner] The linter 'maligned' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner. Replaced by govet 'fieldalignment'.
- interfacer # WARN [runner] The linter 'interfacer' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner.
- scopelint # WARN [runner] The linter 'scopelint' is deprecated (since v1.39.0) due to: The repository of the linter has been deprecated by the owner. Replaced by exportloopref.
- tagliatelle
- wsl
- goerr113
- nlreturn
- lll
- godot
- exhaustivestruct
- exhaustruct
- varnamelen
- ireturn
- dupl
- wrapcheck
- testpackage
- godox
- nestif
- funlen
- gocognit
- gocyclo
- gomnd
- nonamedreturns
- gochecknoglobals
- revive
- stylecheck
- gocritic
run:
timeout: 3m
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/hirosassa/zerodriver

go 1.17
go 1.19

require (
bou.ke/monkey v1.0.2
Expand Down
23 changes: 15 additions & 8 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package zerodriver

import (
"bytes"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestHTTP(t *testing.T) {
func TestNewHTTP(t *testing.T) {
t.Parallel()

var tests = map[string]struct {
tests := map[string]struct {
req *http.Request
res *http.Response
want *HTTPPayload
Expand All @@ -69,20 +69,22 @@ func TestNewHTTP(t *testing.T) {
&HTTPPayload{RequestURL: "https://example.com"},
},
"RequestSize": {
&http.Request{ContentLength: 5, Body: ioutil.NopCloser(strings.NewReader("12345"))},
&http.Request{ContentLength: 5, Body: io.NopCloser(strings.NewReader("12345"))},
nil,
&HTTPPayload{RequestSize: "5"},
},

"ResponseSize": {
nil,
&http.Response{ContentLength: 5, Body: ioutil.NopCloser(strings.NewReader("12345"))},
&http.Response{ContentLength: 5, Body: io.NopCloser(strings.NewReader("12345"))},
&HTTPPayload{ResponseSize: "5"},
},
}

for name, tt := range tests {
tt := tt
t.Run(name, func(t *testing.T) {
t.Parallel()
if diff := cmp.Diff(tt.want, NewHTTP(tt.req, tt.res)); diff != "" {
t.Errorf("HTTPPayload differs (-got +want)\n%s", diff)
}
Expand All @@ -92,7 +94,7 @@ func TestNewHTTP(t *testing.T) {

func TestMakeLatency(t *testing.T) {
t.Parallel()
var tests = map[string]struct {
tests := map[string]struct {
d time.Duration
isGKE bool
want Latency
Expand All @@ -110,17 +112,18 @@ func TestMakeLatency(t *testing.T) {
}

for name, tt := range tests {
tt := tt
t.Run(name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tt.want, MakeLatency(tt.d, tt.isGKE))
})
}

}

func TestMakeGAELatency(t *testing.T) {
t.Parallel()

var tests = map[string]struct {
tests := map[string]struct {
d time.Duration
want GAELatency
}{
Expand All @@ -139,7 +142,9 @@ func TestMakeGAELatency(t *testing.T) {
}

for name, tt := range tests {
tt := tt
t.Run(name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tt.want, makeGAELatency(tt.d))
})
}
Expand All @@ -148,7 +153,7 @@ func TestMakeGAELatency(t *testing.T) {
func TestRemoteIP(t *testing.T) {
t.Parallel()

var tests = map[string]struct {
tests := map[string]struct {
req *http.Request
want string
}{
Expand All @@ -172,7 +177,9 @@ func TestRemoteIP(t *testing.T) {
},
}
for name, tt := range tests {
tt := tt
t.Run(name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tt.want, remoteIP(tt.req))
})
}
Expand Down
8 changes: 8 additions & 0 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import (
)

func TestNewProduction(t *testing.T) {
t.Parallel()
logger := NewProductionLogger()
assert.IsType(t, &Logger{}, logger)
}

func TestNewDevelopment(t *testing.T) {
t.Parallel()
logger := NewDevelopmentLogger()
assert.IsType(t, &Logger{}, logger)
}
Expand Down Expand Up @@ -66,7 +68,9 @@ func TestLoggers(t *testing.T) {
},
}
for name, tt := range tests {
tt := tt
t.Run(name, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tt.want, tt.res)
})
}
Expand Down Expand Up @@ -124,6 +128,8 @@ func TestPanic(t *testing.T) {
}

func TestPrint(t *testing.T) {
t.Parallel()

// replace writer
log := NewDevelopmentLogger()
out := &bytes.Buffer{}
Expand All @@ -141,6 +147,8 @@ func TestPrint(t *testing.T) {
}

func TestPrintf(t *testing.T) {
t.Parallel()

// replace writer
log := NewDevelopmentLogger()
out := &bytes.Buffer{}
Expand Down

0 comments on commit e5d03f7

Please sign in to comment.