Skip to content

Commit

Permalink
add explanation and nolint for require in http tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTylerHolmes committed Dec 10, 2024
1 parent 10cffb9 commit 47b5d03
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions server/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ func TestGetPayload(t *testing.T) {
} else {
w.WriteHeader(http.StatusInternalServerError)
_, err := w.Write([]byte(`{"code":500,"message":"internal server error"}`))
require.NoError(t, err)
require.NoError(t, err, "failed to write error response") //nolint:testifylint // if we fail here the test is compromised
}
count++
})
Expand All @@ -704,7 +704,7 @@ func TestGetPayload(t *testing.T) {
} else {
w.WriteHeader(http.StatusInternalServerError)
_, err := w.Write([]byte(`{"code":500,"message":"internal server error"}`))
require.NoError(t, err)
require.NoError(t, err, "failed to write error response") //nolint:testifylint // if we fail here the test is compromised
}
})
rr := backend.request(t, http.MethodPost, path, payload)
Expand Down
6 changes: 3 additions & 3 deletions server/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestSendHTTPRequestUserAgent(t *testing.T) {
customUA := "test-user-agent"
expectedUA := fmt.Sprintf("mev-boost/%s %s", config.Version, customUA)
ts := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
require.Equal(t, expectedUA, r.Header.Get("User-Agent"))
require.Equal(t, expectedUA, r.Header.Get("User-Agent")) //nolint:testifylint // if we fail here the test has failed
done <- true
}))
code, err := SendHTTPRequest(context.Background(), *http.DefaultClient, http.MethodGet, ts.URL, UserAgent(customUA), nil, nil, nil)
Expand All @@ -58,7 +58,7 @@ func TestSendHTTPRequestUserAgent(t *testing.T) {
// Test without custom UA
expectedUA = fmt.Sprintf("mev-boost/%s", config.Version)
ts = httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
require.Equal(t, expectedUA, r.Header.Get("User-Agent"))
require.Equal(t, expectedUA, r.Header.Get("User-Agent")) //nolint:testifylint // if we fail here the test has failed
done <- true
}))
code, err = SendHTTPRequest(context.Background(), *http.DefaultClient, http.MethodGet, ts.URL, "", nil, nil, nil)
Expand All @@ -77,7 +77,7 @@ func TestSendHTTPRequestGzip(t *testing.T) {
require.NoError(t, zw.Close())

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "gzip", r.Header.Get("Accept-Encoding"))
require.Equal(t, "gzip", r.Header.Get("Accept-Encoding")) //nolint:testifylint // if this fails the test is invalid
w.Header().Set("Content-Encoding", "gzip")
_, _ = w.Write(buf.Bytes())
}))
Expand Down

0 comments on commit 47b5d03

Please sign in to comment.