Skip to content

Commit

Permalink
chore: update dependecy, CI, and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 25, 2024
1 parent 842f413 commit ee138e5
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
env:
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.55.2
GOLANGCI_LINT_VERSION: v1.57.1

steps:

Expand Down
22 changes: 17 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
run:
deadline: 5m
skip-files: [ ]
skip-dirs: ["internal/holsterv4"]
timeout: 5m

linters-settings:
govet:
Expand All @@ -11,8 +9,6 @@ linters-settings:
- shadow
gocyclo:
min-complexity: 15
maligned:
suggest-new: true
goconst:
min-len: 5
min-occurrences: 3
Expand Down Expand Up @@ -50,6 +46,9 @@ linters-settings:
settings:
hugeParam:
sizeThreshold: 100
testifylint:
disable:
- go-require

linters:
enable-all: true
Expand Down Expand Up @@ -92,11 +91,24 @@ linters:
- nonamedreturns
- gochecknoglobals # TODO(ldez) should be use on the project
- nestif # TODO(ldez) should be use on the project
- musttag
- perfsprint # TODO(ldez) should be use on the project
- copyloopvar # TODO(ldez) should be use on the project (only for go>=1.22)
- intrange # TODO(ldez) should be use on the project (only for go>=1.22)

output:
show-stats: true
sort-results: true
sort-order:
- linter
- file

issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
exclude-dirs:
- "internal/holsterv4"
exclude:
- 'ST1000: at least one file in a package should have a package comment' # TODO(ldez) must be fixed
- 'package-comments: should have a package comment'
Expand Down
28 changes: 14 additions & 14 deletions buffer/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

func TestSimple(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})
t.Cleanup(srv.Close)
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestChunkedEncodingSuccess(t *testing.T) {
}

func TestChunkedEncodingLimitReached(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})
t.Cleanup(srv.Close)
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestChunkedEncodingLimitReached(t *testing.T) {
}

func TestChunkedResponse(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
h := w.(http.Hijacker)
conn, _, _ := h.Hijack()
_, _ = fmt.Fprintf(conn, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n4\r\ntest\r\n5\r\ntest1\r\n5\r\ntest2\r\n0\r\n\r\n")
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestChunkedResponse(t *testing.T) {
}

func TestRequestLimitReached(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})
t.Cleanup(srv.Close)
Expand All @@ -173,7 +173,7 @@ func TestRequestLimitReached(t *testing.T) {
}

func TestResponseLimitReached(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello, this response is too large"))
})
t.Cleanup(srv.Close)
Expand All @@ -200,7 +200,7 @@ func TestResponseLimitReached(t *testing.T) {
}

func TestFileStreamingResponse(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello, this response is too large to fit in memory"))
})
t.Cleanup(srv.Close)
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestFileStreamingResponse(t *testing.T) {
}

func TestCustomErrorHandler(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello, this response is too large"))
})
t.Cleanup(srv.Close)
Expand All @@ -243,7 +243,7 @@ func TestCustomErrorHandler(t *testing.T) {
})

// stream handler will forward requests to redirect
errHandler := utils.ErrorHandlerFunc(func(w http.ResponseWriter, req *http.Request, err error) {
errHandler := utils.ErrorHandlerFunc(func(w http.ResponseWriter, _ *http.Request, _ error) {
w.WriteHeader(http.StatusTeapot)
_, _ = w.Write([]byte(http.StatusText(http.StatusTeapot)))
})
Expand All @@ -259,7 +259,7 @@ func TestCustomErrorHandler(t *testing.T) {
}

func TestNotModified(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusNotModified)
})
t.Cleanup(srv.Close)
Expand All @@ -286,7 +286,7 @@ func TestNotModified(t *testing.T) {
}

func TestNoBody(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
})
t.Cleanup(srv.Close)
Expand Down Expand Up @@ -314,7 +314,7 @@ func TestNoBody(t *testing.T) {

// Make sure that stream handler preserves TLS settings.
func TestPreservesTLS(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
})
Expand Down Expand Up @@ -346,7 +346,7 @@ func TestPreservesTLS(t *testing.T) {
}

func TestNotNilBody(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})
t.Cleanup(srv.Close)
Expand Down Expand Up @@ -382,7 +382,7 @@ func TestNotNilBody(t *testing.T) {
}

func TestGRPCErrorResponse(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Grpc-Status", "10" /* ABORTED */)
w.WriteHeader(http.StatusOK)

Expand Down Expand Up @@ -414,7 +414,7 @@ func TestGRPCErrorResponse(t *testing.T) {
}

func TestGRPCOKResponse(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Grpc-Status", "0" /* OK */)
_, _ = w.Write([]byte("grpc-body"))
w.WriteHeader(http.StatusOK)
Expand Down
6 changes: 3 additions & 3 deletions buffer/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestSuccess(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})
t.Cleanup(srv.Close)
Expand All @@ -32,7 +32,7 @@ func TestSuccess(t *testing.T) {
}

func TestRetryOnError(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})
t.Cleanup(srv.Close)
Expand All @@ -52,7 +52,7 @@ func TestRetryOnError(t *testing.T) {
}

func TestRetryExceedAttempts(t *testing.T) {
srv := testutils.NewHandler(func(w http.ResponseWriter, req *http.Request) {
srv := testutils.NewHandler(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})
t.Cleanup(srv.Close)
Expand Down
16 changes: 8 additions & 8 deletions cbreaker/cbreaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
const triggerNetRatio = `NetworkErrorRatio() > 0.5`

func TestStandbyCycle(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})

Expand All @@ -36,7 +36,7 @@ func TestStandbyCycle(t *testing.T) {
}

func TestFullCycle(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})

Expand Down Expand Up @@ -93,7 +93,7 @@ func TestFullCycle(t *testing.T) {
}

func TestRedirectWithPath(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})

Expand All @@ -114,7 +114,7 @@ func TestRedirectWithPath(t *testing.T) {
require.NoError(t, err)

client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return fmt.Errorf("no redirects")
},
}
Expand All @@ -126,7 +126,7 @@ func TestRedirectWithPath(t *testing.T) {
}

func TestRedirect(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})

Expand All @@ -144,7 +144,7 @@ func TestRedirect(t *testing.T) {
require.NoError(t, err)

client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return fmt.Errorf("no redirects")
},
}
Expand All @@ -156,7 +156,7 @@ func TestRedirect(t *testing.T) {
}

func TestTriggerDuringRecovery(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})

Expand Down Expand Up @@ -233,7 +233,7 @@ func TestSideEffects(t *testing.T) {
})
require.NoError(t, err)

handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})

Expand Down
2 changes: 1 addition & 1 deletion cbreaker/ratio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestRampUp(t *testing.T) {
t.Log("Ratio", ratio)
t.Log("Expected", expected)
t.Log("Diff", diff)
assert.EqualValues(t, 0, round(diff, 0.5, 1))
assert.EqualValues(t, 0, round(diff, 0.5, 1)) //nolint:testifylint // the rounding is already handled.
clock.Advance(clock.Millisecond)
}
}
Expand Down
6 changes: 3 additions & 3 deletions connlimit/connlimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ func TestHitLimitAndRelease(t *testing.T) {

// We've hit the limit and were able to proceed once the request has completed.
func TestCustomHandlers(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})

errHandler := utils.ErrorHandlerFunc(func(w http.ResponseWriter, req *http.Request, err error) {
errHandler := utils.ErrorHandlerFunc(func(w http.ResponseWriter, _ *http.Request, _ error) {
w.WriteHeader(http.StatusTeapot)
_, _ = w.Write([]byte(http.StatusText(http.StatusTeapot)))
})
Expand All @@ -84,7 +84,7 @@ func TestCustomHandlers(t *testing.T) {

// We've hit the limit and were able to proceed once the request has completed.
func TestFaultyExtract(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
})

Expand Down
8 changes: 4 additions & 4 deletions forward/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func ExampleNew_customErrHandler() {
f := New(true)
f.ErrorHandler = func(w http.ResponseWriter, req *http.Request, err error) {
f.ErrorHandler = func(w http.ResponseWriter, _ *http.Request, _ error) {
w.WriteHeader(http.StatusTeapot)
_, _ = w.Write([]byte(http.StatusText(http.StatusTeapot)))
}
Expand Down Expand Up @@ -43,7 +43,7 @@ func ExampleNew_customErrHandler() {
}

func ExampleNew_responseModifier() {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
}))
defer srv.Close()
Expand Down Expand Up @@ -75,7 +75,7 @@ func ExampleNew_responseModifier() {
}

func ExampleNew_customTransport() {
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
}))
defer srv.Close()
Expand Down Expand Up @@ -113,7 +113,7 @@ func ExampleNew_customTransport() {
}

func ExampleNewStateListener() {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("hello"))
}))
defer srv.Close()
Expand Down
4 changes: 2 additions & 2 deletions forward/fwd_websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestWebSocketPassHost(t *testing.T) {
func TestWebSocketServerWithoutCheckOrigin(t *testing.T) {
f := New(true)

upgrader := gorillawebsocket.Upgrader{CheckOrigin: func(r *http.Request) bool {
upgrader := gorillawebsocket.Upgrader{CheckOrigin: func(_ *http.Request) bool {
return true
}}
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestWebSocketUpgradeFailed(t *testing.T) {
f := New(true)

mux := http.NewServeMux()
mux.HandleFunc("/ws", func(w http.ResponseWriter, req *http.Request) {
mux.HandleFunc("/ws", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusBadRequest)
})

Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require (
github.com/gorilla/websocket v1.5.1
github.com/mailgun/multibuf v0.1.2
github.com/segmentio/fasthash v1.0.3
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/vulcand/predicate v1.2.0
golang.org/x/net v0.20.0
golang.org/x/net v0.22.0
)

require (
Expand All @@ -18,8 +18,8 @@ require (
github.com/jonboulle/clockwork v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit ee138e5

Please sign in to comment.