Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linters that check for bugs #310

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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