Skip to content

Commit

Permalink
Add linters that check for bugs (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome authored Jul 10, 2024
1 parent d4b83da commit 052c7d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ linters:
- asasalint
- asciicheck
- bidichk
- contextcheck
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exportloopref
- fatcontext
- forcetypeassert
- gocheckcompilerdirectives
- gochecksumtype
- gocritic
- godot
- gofmt
- gofumpt
Expand All @@ -54,6 +59,7 @@ linters:
- intrange
- makezero
- misspell
- musttag
- nilerr
- noctx
- nolintlint
Expand Down
12 changes: 6 additions & 6 deletions client/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ type StreamUpstreamServer struct {
}

type apiErrorResponse struct {
RequestID string `json:"request_id"`
Href string
Error apiError
RequestID string `json:"request_id"`
Href string `json:"href"`
Error apiError `json:"error"`
}

func (resp *apiErrorResponse) toString() string {
Expand All @@ -94,9 +94,9 @@ func (resp *apiErrorResponse) toString() string {
}

type apiError struct {
Text string
Code string
Status int
Text string `json:"text"`
Code string `json:"code"`
Status int `json:"status"`
}

type internalError struct {
Expand Down
18 changes: 10 additions & 8 deletions client/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,19 +602,20 @@ func TestClientWithHTTPClient(t *testing.T) {
func TestGetStats_NoStreamEndpoint(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/" {
switch {
case r.RequestURI == "/":
_, err := w.Write([]byte(`[4, 5, 6, 7, 8, 9]`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
} else if r.RequestURI == "/7/" {
case r.RequestURI == "/7/":
_, err := w.Write([]byte(`["nginx","processes","connections","slabs","http","resolvers","ssl"]`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
} else if strings.HasPrefix(r.RequestURI, "/7/stream") {
case strings.HasPrefix(r.RequestURI, "/7/stream"):
t.Fatal("Stream endpoint should not be called since it does not exist.")
} else {
default:
_, err := w.Write([]byte(`{}`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand Down Expand Up @@ -654,17 +655,18 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) {
func TestGetStats_SSL(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/" {
switch {
case r.RequestURI == "/":
_, err := w.Write([]byte(`[4, 5, 6, 7, 8, 9]`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
} else if r.RequestURI == "/8/" {
case r.RequestURI == "/8/":
_, err := w.Write([]byte(`["nginx","processes","connections","slabs","http","resolvers","ssl","workers"]`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
} else if strings.HasPrefix(r.RequestURI, "/8/ssl") {
case strings.HasPrefix(r.RequestURI, "/8/ssl"):
_, err := w.Write([]byte(`{
"handshakes" : 79572,
"handshakes_failed" : 21025,
Expand All @@ -684,7 +686,7 @@ func TestGetStats_SSL(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
} else {
default:
_, err := w.Write([]byte(`{}`))
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand Down

0 comments on commit 052c7d8

Please sign in to comment.