Skip to content

Commit

Permalink
lint: a lot of small "unused param" fixes, mostly in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Feb 9, 2024
1 parent 7f7ba91 commit be89668
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion benchmarks_test.go
Expand Up @@ -131,7 +131,7 @@ func TestBenchmark_Cleanup(t *testing.T) {
}

func TestBenchmarks_Handler(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
time.Sleep(time.Millisecond * 50)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion blackwords.go
Expand Up @@ -17,7 +17,7 @@ func BlackWords(words ...string) func(http.Handler) http.Handler {
body := strings.ToLower(string(content))
r.Body = io.NopCloser(bytes.NewReader(content))

if len(body) > 0 {
if body != "" {
for _, word := range words {
if strings.Contains(body, strings.ToLower(word)) {
w.WriteHeader(http.StatusForbidden)
Expand Down
4 changes: 2 additions & 2 deletions cache_control_test.go
Expand Up @@ -31,7 +31,7 @@ func TestRest_cacheControl(t *testing.T) {
req := httptest.NewRequest("GET", tt.url, http.NoBody)
w := httptest.NewRecorder()

h := CacheControl(tt.exp, tt.version)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
h := CacheControl(tt.exp, tt.version)(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {}))
h.ServeHTTP(w, req)
resp := w.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestCacheControlDynamic(t *testing.T) {
fn := func(r *http.Request) string {
return r.Header.Get("key")
}
h := CacheControlDynamic(tt.exp, fn)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
h := CacheControlDynamic(tt.exp, fn)(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {}))
h.ServeHTTP(w, req)
resp := w.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)
Expand Down
4 changes: 2 additions & 2 deletions gzip_test.go
Expand Up @@ -14,7 +14,7 @@ import (
)

func TestGzipCustom(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. " +
"Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took " +
"a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries," +
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestGzipCustom(t *testing.T) {
}

func TestGzipDefault(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. " +
"Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took " +
"a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries," +
Expand Down
2 changes: 1 addition & 1 deletion logger/logger.go
Expand Up @@ -226,7 +226,7 @@ func (l *Middleware) getBody(r *http.Request) string {
// https://golang.org/pkg/net/http/#Handler
r.Body = io.NopCloser(reader)

if len(body) > 0 {
if body != "" {
body = strings.Replace(body, "\n", " ", -1)
body = reMultWhtsp.ReplaceAllString(body, " ")
}
Expand Down
26 changes: 13 additions & 13 deletions logger/logger_test.go
Expand Up @@ -19,7 +19,7 @@ import (

func TestLoggerMinimal(t *testing.T) {

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestLoggerMinimal(t *testing.T) {

func TestLoggerMinimalLocalhost(t *testing.T) {

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestLoggerMinimalLocalhost(t *testing.T) {

func TestLogger(t *testing.T) {

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand All @@ -90,10 +90,10 @@ func TestLogger(t *testing.T) {
IPfn(func(ip string) string {
return ip + "!masked"
}),
UserFn(func(r *http.Request) (string, error) {
UserFn(func(*http.Request) (string, error) {
return "user", nil
}),
SubjFn(func(r *http.Request) (string, error) {
SubjFn(func(*http.Request) (string, error) {
return "subj", nil
}),
)
Expand All @@ -116,7 +116,7 @@ func TestLogger(t *testing.T) {
}

func TestLoggerIP(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestLoggerIP(t *testing.T) {
}

func TestLoggerIPAnon(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestLoggerIPAnon(t *testing.T) {
}

func TestLoggerTraceID(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand All @@ -197,10 +197,10 @@ func TestLoggerTraceID(t *testing.T) {
IPfn(func(ip string) string {
return ip + "!masked"
}),
UserFn(func(r *http.Request) (string, error) {
UserFn(func(*http.Request) (string, error) {
return "user", nil
}),
SubjFn(func(r *http.Request) (string, error) {
SubjFn(func(*http.Request) (string, error) {
return "subj", nil
}),
)
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestLoggerMaxBodySize(t *testing.T) {
}

func TestLoggerDefault(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand Down Expand Up @@ -375,7 +375,7 @@ func TestSanitizeReqURL(t *testing.T) {

func TestLoggerApacheCombined(t *testing.T) {

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand All @@ -385,7 +385,7 @@ func TestLoggerApacheCombined(t *testing.T) {
IPfn(func(ip string) string {
return ip + "!masked"
}),
UserFn(func(r *http.Request) (string, error) {
UserFn(func(*http.Request) (string, error) {
return "user", nil
}),
)
Expand Down
4 changes: 2 additions & 2 deletions metrics_test.go
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestMetrics(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand All @@ -31,7 +31,7 @@ func TestMetrics(t *testing.T) {
}

func TestMetricsRejected(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand Down
28 changes: 14 additions & 14 deletions middleware_test.go
Expand Up @@ -23,7 +23,7 @@ func TestMiddleware_AppInfo(t *testing.T) {
err := os.Setenv("MHOST", "host1")
assert.NoError(t, err)

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err = w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand All @@ -47,7 +47,7 @@ func TestMiddleware_AppInfo(t *testing.T) {

func TestMiddleware_Ping(t *testing.T) {

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestMiddleware_Recoverer(t *testing.T) {
}

func TestWrap(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
t.Logf("%s", r.URL.String())
assert.Equal(t, "/something/1/2", r.URL.Path)
})
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestHeaders(t *testing.T) {
req := httptest.NewRequest("GET", "/something", http.NoBody)
w := httptest.NewRecorder()

h := Headers("h1:v1", "bad", "h2:v2")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
h := Headers("h1:v1", "bad", "h2:v2")(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {}))
h.ServeHTTP(w, req)
resp := w.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)
Expand All @@ -148,9 +148,9 @@ func TestHeaders(t *testing.T) {

func TestMaybe(t *testing.T) {
var count int32
h := Maybe(Headers("h1:v1", "bad", "h2:v2"), func(r *http.Request) bool {
h := Maybe(Headers("h1:v1", "bad", "h2:v2"), func(*http.Request) bool {
return atomic.AddInt32(&count, 1) == 1
})(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
})(http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {}))

{
req := httptest.NewRequest("GET", "/something", http.NoBody)
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestMaybe(t *testing.T) {

func TestRealIP(t *testing.T) {

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
t.Logf("%v", r)
require.Equal(t, "1.2.3.4", r.RemoteAddr)
adr, err := realip.Get(r)
Expand All @@ -199,15 +199,15 @@ func TestRealIP(t *testing.T) {
}

func TestHealthPassed(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})

check1 := func(ctx context.Context) (string, error) {
check1 := func(context.Context) (string, error) {
return "check1", nil
}
check2 := func(ctx context.Context) (string, error) {
check2 := func(context.Context) (string, error) {
return "check2", nil
}

Expand All @@ -232,15 +232,15 @@ func TestHealthPassed(t *testing.T) {
}

func TestHealthFailed(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})

check1 := func(ctx context.Context) (string, error) {
check1 := func(context.Context) (string, error) {
return "check1", nil
}
check2 := func(ctx context.Context) (string, error) {
check2 := func(context.Context) (string, error) {
return "check2", errors.New("some error")
}

Expand All @@ -257,7 +257,7 @@ func TestHealthFailed(t *testing.T) {
}

func TestReject(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand Down
2 changes: 1 addition & 1 deletion nocache_test.go
Expand Up @@ -12,7 +12,7 @@ import (
func TestNoCache(t *testing.T) {

rr := httptest.NewRecorder()
testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
testHandler := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
t.Logf("%+v", r)
})

Expand Down
10 changes: 5 additions & 5 deletions onlyfrom_test.go
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestOnlyFromAllowedIP(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand All @@ -29,7 +29,7 @@ func TestOnlyFromAllowedIP(t *testing.T) {
}

func TestOnlyFromAllowedHeaders(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestOnlyFromAllowedHeaders(t *testing.T) {

func TestOnlyFromAllowedCIDR(t *testing.T) {

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand All @@ -100,7 +100,7 @@ func TestOnlyFromAllowedCIDR(t *testing.T) {
}

func TestOnlyFromRejected(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestOnlyFromErrors(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.RemoteAddr = tt.remoteAddr
OnlyFrom("1.1.1.1")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
OnlyFrom("1.1.1.1")(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte("blah blah"))
require.NoError(t, err)
})).ServeHTTP(w, r)
Expand Down
2 changes: 1 addition & 1 deletion realip/real_test.go
Expand Up @@ -130,7 +130,7 @@ func TestGetFromHeaders(t *testing.T) {
}

func TestGetFromRemoteAddr(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
log.Printf("%v", r)
adr, err := Get(r)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions rest_test.go
Expand Up @@ -16,7 +16,7 @@ import (
)

func TestRest_RenderJSON(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
j := JSON{"key1": 1, "key2": "222"}
RenderJSON(w, j)
}))
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestEncodeJSONResponse(t *testing.T) {
}

func getTestHandlerBlah() http.HandlerFunc {
fn := func(rw http.ResponseWriter, req *http.Request) {
fn := func(rw http.ResponseWriter, _ *http.Request) {
_, _ = rw.Write([]byte("blah"))
}
return fn
Expand Down
6 changes: 3 additions & 3 deletions rewrite_test.go
Expand Up @@ -12,7 +12,7 @@ import (
func TestRewrite(t *testing.T) {

rr := httptest.NewRecorder()
testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
testHandler := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
t.Logf("%+v", r)
assert.Equal(t, "/xyzzz/params?foo=bar", r.URL.String())
assert.Equal(t, "/xyzzz/params", r.URL.Path)
Expand All @@ -28,7 +28,7 @@ func TestRewrite(t *testing.T) {
func TestRewriteCleanup(t *testing.T) {

rr := httptest.NewRecorder()
testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
testHandler := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
t.Logf("%+v", r)
assert.Equal(t, "/xyzzz/params?foo=bar", r.URL.String())
assert.Equal(t, "/xyzzz/params", r.URL.Path)
Expand All @@ -44,7 +44,7 @@ func TestRewriteCleanup(t *testing.T) {
func TestRewriteCleanupWithSlash(t *testing.T) {

rr := httptest.NewRecorder()
testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
testHandler := http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
t.Logf("%+v", r)
assert.Equal(t, "/xyzzz/params/", r.URL.String())
assert.Equal(t, "/xyzzz/params/", r.URL.Path)
Expand Down

0 comments on commit be89668

Please sign in to comment.