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

@@ -13,7 +13,7 @@ import (
)
func TestAuthHandlerFailed(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
handler := Authorize("B63F477D-BBA3-4E52-96D3-C0034C27694A", WithUnauthorizedCallback(
func(w http.ResponseWriter, r *http.Request, err error) {
assert.NotNil(t, err)
@@ -33,7 +33,7 @@ func TestAuthHandlerFailed(t *testing.T) {
func TestAuthHandler(t *testing.T) {
const key = "B63F477D-BBA3-4E52-96D3-C0034C27694A"
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
token, err := buildToken(key, map[string]interface{}{
"key": "value",
}, 3600)
@@ -62,7 +62,7 @@ func TestAuthHandlerWithPrevSecret(t *testing.T) {
key = "14F17379-EB8F-411B-8F12-6929002DCA76"
prevKey = "B63F477D-BBA3-4E52-96D3-C0034C27694A"
)
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
token, err := buildToken(key, map[string]interface{}{
"key": "value",
}, 3600)
@@ -83,7 +83,7 @@ func TestAuthHandlerWithPrevSecret(t *testing.T) {
}
func TestAuthHandler_NilError(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
assert.NotPanics(t, func() {
unauthorized(resp, req, nil, nil)

View File

@@ -25,7 +25,7 @@ func TestBreakerHandlerAccept(t *testing.T) {
assert.Nil(t, err)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
req.Header.Set("X-Test", "test")
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
@@ -41,7 +41,7 @@ func TestBreakerHandlerFail(t *testing.T) {
w.WriteHeader(http.StatusBadGateway)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusBadGateway, resp.Code)
@@ -55,7 +55,7 @@ func TestBreakerHandler_4XX(t *testing.T) {
}))
for i := 0; i < 1000; i++ {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
}
@@ -63,7 +63,7 @@ func TestBreakerHandler_4XX(t *testing.T) {
const tries = 100
var pass int
for i := 0; i < tries; i++ {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
if resp.Code == http.StatusBadRequest {
@@ -82,14 +82,14 @@ func TestBreakerHandlerReject(t *testing.T) {
}))
for i := 0; i < 1000; i++ {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
}
var drops int
for i := 0; i < 100; i++ {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
if resp.Code == http.StatusServiceUnavailable {

View File

@@ -26,7 +26,7 @@ func init() {
}
func TestCryptionHandlerGet(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/any", nil)
req := httptest.NewRequest(http.MethodGet, "/any", http.NoBody)
handler := CryptionHandler(aesKey)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte(respText))
w.Header().Set("X-Test", "test")
@@ -80,7 +80,7 @@ func TestCryptionHandlerPostBadEncryption(t *testing.T) {
}
func TestCryptionHandlerWriteHeader(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/any", nil)
req := httptest.NewRequest(http.MethodGet, "/any", http.NoBody)
handler := CryptionHandler(aesKey)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusServiceUnavailable)
}))
@@ -90,7 +90,7 @@ func TestCryptionHandlerWriteHeader(t *testing.T) {
}
func TestCryptionHandlerFlush(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/any", nil)
req := httptest.NewRequest(http.MethodGet, "/any", http.NoBody)
handler := CryptionHandler(aesKey)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(respText))
flusher, ok := w.(http.Flusher)

View File

@@ -24,7 +24,7 @@ func TestLogHandler(t *testing.T) {
}
for _, logHandler := range handlers {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
handler := logHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.Context().Value(internal.LogContext).(*internal.LogCollector).Append("anything")
w.Header().Set("X-Test", "test")
@@ -79,7 +79,7 @@ func TestLogHandlerSlow(t *testing.T) {
}
for _, logHandler := range handlers {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
handler := logHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(defaultSlowThreshold + time.Millisecond*50)
}))
@@ -159,7 +159,7 @@ func TestWrapStatusCodeWithColor(t *testing.T) {
func BenchmarkLogHandler(b *testing.B) {
b.ReportAllocs()
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
handler := LogHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}))

View File

@@ -32,13 +32,13 @@ func TestMaxConnsHandler(t *testing.T) {
for i := 0; i < conns; i++ {
go func() {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
handler.ServeHTTP(httptest.NewRecorder(), req)
}()
}
waitGroup.Wait()
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusServiceUnavailable, resp.Code)
@@ -65,14 +65,14 @@ func TestWithoutMaxConnsHandler(t *testing.T) {
for i := 0; i < conns; i++ {
go func() {
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
req.Header.Set(key, value)
handler.ServeHTTP(httptest.NewRecorder(), req)
}()
}
waitGroup.Wait()
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusOK, resp.Code)

View File

@@ -16,7 +16,7 @@ func TestMetricHandler(t *testing.T) {
w.WriteHeader(http.StatusOK)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusOK, resp.Code)

View File

@@ -15,7 +15,7 @@ func TestPromMetricHandler_Disabled(t *testing.T) {
w.WriteHeader(http.StatusOK)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusOK, resp.Code)
@@ -31,7 +31,7 @@ func TestPromMetricHandler_Enabled(t *testing.T) {
w.WriteHeader(http.StatusOK)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusOK, resp.Code)

View File

@@ -19,7 +19,7 @@ func TestWithPanic(t *testing.T) {
panic("whatever")
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusInternalServerError, resp.Code)
@@ -29,7 +29,7 @@ func TestWithoutPanic(t *testing.T) {
handler := RecoverHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusOK, resp.Code)

View File

@@ -28,7 +28,7 @@ func TestSheddingHandlerAccept(t *testing.T) {
assert.Nil(t, err)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
req.Header.Set("X-Test", "test")
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
@@ -47,7 +47,7 @@ func TestSheddingHandlerFail(t *testing.T) {
w.WriteHeader(http.StatusServiceUnavailable)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusServiceUnavailable, resp.Code)
@@ -63,7 +63,7 @@ func TestSheddingHandlerReject(t *testing.T) {
w.WriteHeader(http.StatusOK)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusServiceUnavailable, resp.Code)
@@ -76,7 +76,7 @@ func TestSheddingHandlerNoShedding(t *testing.T) {
w.WriteHeader(http.StatusOK)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusOK, resp.Code)

View File

@@ -22,7 +22,7 @@ func TestTimeout(t *testing.T) {
time.Sleep(time.Minute)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusServiceUnavailable, resp.Code)
@@ -34,7 +34,7 @@ func TestWithinTimeout(t *testing.T) {
time.Sleep(time.Millisecond)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusOK, resp.Code)
@@ -48,7 +48,7 @@ func TestWithTimeoutTimedout(t *testing.T) {
w.WriteHeader(http.StatusOK)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusServiceUnavailable, resp.Code)
@@ -60,7 +60,7 @@ func TestWithoutTimeout(t *testing.T) {
time.Sleep(100 * time.Millisecond)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusOK, resp.Code)
@@ -72,7 +72,7 @@ func TestTimeoutPanic(t *testing.T) {
panic("foo")
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
assert.Panics(t, func() {
handler.ServeHTTP(resp, req)
@@ -85,7 +85,7 @@ func TestTimeoutWebsocket(t *testing.T) {
time.Sleep(time.Millisecond * 10)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
req.Header.Set(headerUpgrade, valueWebsocket)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
@@ -100,7 +100,7 @@ func TestTimeoutWroteHeaderTwice(t *testing.T) {
w.WriteHeader(http.StatusOK)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusOK, resp.Code)
@@ -112,7 +112,7 @@ func TestTimeoutWriteBadCode(t *testing.T) {
w.WriteHeader(1000)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
resp := httptest.NewRecorder()
assert.Panics(t, func() {
handler.ServeHTTP(resp, req)
@@ -125,7 +125,7 @@ func TestTimeoutClientClosed(t *testing.T) {
w.WriteHeader(http.StatusServiceUnavailable)
}))
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
ctx, cancel := context.WithCancel(context.Background())
req = req.WithContext(ctx)
cancel()