chore: fix lint errors (#2520)

This commit is contained in:
Kevin Wan
2022-10-17 06:30:58 +08:00
committed by GitHub
parent d4c9fd2aff
commit 05a5de7c6d
27 changed files with 117 additions and 148 deletions

View File

@@ -65,7 +65,7 @@ func TestCorsHandlerWithOrigins(t *testing.T) {
for _, method := range methods {
test := test
t.Run(test.name+"-handler", func(t *testing.T) {
r := httptest.NewRequest(method, "http://localhost", nil)
r := httptest.NewRequest(method, "http://localhost", http.NoBody)
r.Header.Set(originHeader, test.reqOrigin)
w := httptest.NewRecorder()
handler := NotAllowedHandler(nil, test.origins...)
@@ -78,7 +78,7 @@ func TestCorsHandlerWithOrigins(t *testing.T) {
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
})
t.Run(test.name+"-handler-custom", func(t *testing.T) {
r := httptest.NewRequest(method, "http://localhost", nil)
r := httptest.NewRequest(method, "http://localhost", http.NoBody)
r.Header.Set(originHeader, test.reqOrigin)
w := httptest.NewRecorder()
handler := NotAllowedHandler(func(w http.ResponseWriter) {
@@ -100,7 +100,7 @@ func TestCorsHandlerWithOrigins(t *testing.T) {
for _, method := range methods {
test := test
t.Run(test.name+"-middleware", func(t *testing.T) {
r := httptest.NewRequest(method, "http://localhost", nil)
r := httptest.NewRequest(method, "http://localhost", http.NoBody)
r.Header.Set(originHeader, test.reqOrigin)
w := httptest.NewRecorder()
handler := Middleware(nil, test.origins...)(func(w http.ResponseWriter, r *http.Request) {
@@ -115,7 +115,7 @@ func TestCorsHandlerWithOrigins(t *testing.T) {
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
})
t.Run(test.name+"-middleware-custom", func(t *testing.T) {
r := httptest.NewRequest(method, "http://localhost", nil)
r := httptest.NewRequest(method, "http://localhost", http.NoBody)
r.Header.Set(originHeader, test.reqOrigin)
w := httptest.NewRecorder()
handler := Middleware(func(header http.Header) {

View File

@@ -14,7 +14,7 @@ func TestParseHeaders(t *testing.T) {
Baz int `header:"baz"`
Qux bool `header:"qux,default=true"`
}
r := httptest.NewRequest(http.MethodGet, "/any", nil)
r := httptest.NewRequest(http.MethodGet, "/any", http.NoBody)
r.Header.Set("foo", "bar")
r.Header.Set("baz", "1")
assert.Nil(t, ParseHeaders(r.Header, &val))
@@ -29,7 +29,7 @@ func TestParseHeadersMulti(t *testing.T) {
Baz int `header:"baz"`
Qux bool `header:"qux,default=true"`
}
r := httptest.NewRequest(http.MethodGet, "/any", nil)
r := httptest.NewRequest(http.MethodGet, "/any", http.NoBody)
r.Header.Set("foo", "bar")
r.Header.Add("foo", "bar1")
r.Header.Set("baz", "1")
@@ -43,7 +43,7 @@ func TestParseHeadersArrayInt(t *testing.T) {
var val struct {
Foo []int `header:"foo"`
}
r := httptest.NewRequest(http.MethodGet, "/any", nil)
r := httptest.NewRequest(http.MethodGet, "/any", http.NoBody)
r.Header.Set("foo", "1")
r.Header.Add("foo", "2")
assert.Nil(t, ParseHeaders(r.Header, &val))

View File

@@ -13,7 +13,7 @@ import (
func TestInfo(t *testing.T) {
collector := new(LogCollector)
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
req = req.WithContext(context.WithValue(req.Context(), LogContext, collector))
Info(req, "first")
Infof(req, "second %s", "third")
@@ -35,7 +35,7 @@ func TestError(t *testing.T) {
logx.SetWriter(o)
}()
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
Error(req, "first")
Errorf(req, "second %s", "third")
val := buf.String()

View File

@@ -11,7 +11,7 @@ import (
)
func TestHeaderOnceResponseWriter_Flush(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cw := NewHeaderOnceResponseWriter(w)
cw.Header().Set("X-Test", "test")

View File

@@ -9,7 +9,7 @@ import (
)
func TestWithCodeResponseWriter(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cw := &WithCodeResponseWriter{Writer: w}