Skip to content

Commit

Permalink
chore: Enable testifylint:go-require checker (influxdata#16158)
Browse files Browse the repository at this point in the history
  • Loading branch information
zak-pawel authored Nov 13, 2024
1 parent 3b705f2 commit cf2a820
Show file tree
Hide file tree
Showing 23 changed files with 1,200 additions and 317 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ linters-settings:
- expected-actual
- float-compare
- formatter
- go-require
- len
- negative-positive
- nil-compare
Expand Down
7 changes: 5 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,11 @@ func TestConfig_AzureMonitorNamespacePrefix(t *testing.T) {
func TestGetDefaultConfigPathFromEnvURL(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("[agent]\ndebug = true"))
require.NoError(t, err)
if _, err := w.Write([]byte("[agent]\ndebug = true")); err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.Error(err)
return
}
}))
defer ts.Close()

Expand Down
7 changes: 5 additions & 2 deletions migrations/inputs_httpjson/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ func TestParsing(t *testing.T) {
// Start the test-server
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/stats" {
_, err = w.Write(input)
require.NoError(t, err)
if _, err = w.Write(input); err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.Error(err)
return
}
} else {
w.WriteHeader(http.StatusNotFound)
}
Expand Down
13 changes: 10 additions & 3 deletions plugins/common/cookie/cookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ func newFakeServer(t *testing.T) fakeServer {
authed()
case authEndpointWithBody:
body, err := io.ReadAll(r.Body)
require.NoError(t, err)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.Error(err)
return
}
if !cmp.Equal([]byte(reqBody), body) {
w.WriteHeader(http.StatusUnauthorized)
return
Expand All @@ -89,8 +93,11 @@ func newFakeServer(t *testing.T) fakeServer {
w.WriteHeader(http.StatusForbidden)
return
}
_, err := w.Write([]byte("good test response"))
require.NoError(t, err)
if _, err := w.Write([]byte("good test response")); err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.Error(err)
return
}
}
})),
int32: &c,
Expand Down
27 changes: 20 additions & 7 deletions plugins/outputs/bigquery/bigquery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,32 @@ func localBigQueryServer(t *testing.T) *httptest.Server {
case "/projects/test-project/datasets/test-dataset/tables/test1/insertAll",
"/projects/test-project/datasets/test-dataset/tables/test-metrics/insertAll":
decoder := json.NewDecoder(r.Body)
require.NoError(t, decoder.Decode(&receivedBody))
if err := decoder.Decode(&receivedBody); err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.Error(err)
return
}

w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(successfulResponse))
require.NoError(t, err)
if _, err := w.Write([]byte(successfulResponse)); err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.Error(err)
return
}
case "/projects/test-project/datasets/test-dataset/tables/test-metrics":
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte("{}"))
require.NoError(t, err)
if _, err := w.Write([]byte("{}")); err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.Error(err)
return
}
default:
w.WriteHeader(http.StatusNotFound)
_, err := w.Write([]byte(r.URL.String()))
require.NoError(t, err)
if _, err := w.Write([]byte(r.URL.String())); err != nil {
w.WriteHeader(http.StatusInternalServerError)
t.Error(err)
return
}
}
})

Expand Down
Loading

0 comments on commit cf2a820

Please sign in to comment.