From 4e58c7b2bd740db4a2c47c3c7ce0417e48afdda6 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 27 Mar 2019 14:46:29 +0000 Subject: [PATCH] chore: fix a bunch of issues caught by golangci-lint Most of these are probably harmless but a few looked like they might actually be bugs. Most of them are just faulty tests. License: MIT Signed-off-by: Steven Allen This commit was moved from ipfs/kubo@1f293eff1b3da26a0c1e4c7d1c45adb88f536dd8 --- gateway/core/corehttp/gateway_test.go | 8 +------- gateway/core/corehttp/mutex_profile.go | 4 ++-- gateway/core/corehttp/option_test.go | 4 +++- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/gateway/core/corehttp/gateway_test.go b/gateway/core/corehttp/gateway_test.go index b44f9ef4f..72193cf52 100644 --- a/gateway/core/corehttp/gateway_test.go +++ b/gateway/core/corehttp/gateway_test.go @@ -43,7 +43,7 @@ func (m mockNamesys) Resolve(ctx context.Context, name string, opts ...nsopts.Re depth = ^uint(0) } for strings.HasPrefix(name, "/ipns/") { - if depth <= 0 { + if depth == 0 { return value, namesys.ErrResolveRecursion } depth-- @@ -235,9 +235,6 @@ func TestGatewayGet(t *testing.T) { } func TestIPNSHostnameRedirect(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - ns := mockNamesys{} ts, api, ctx := newTestServerAndNode(t, ns) t.Logf("test server url: %s", ts.URL) @@ -326,9 +323,6 @@ func TestIPNSHostnameRedirect(t *testing.T) { } func TestIPNSHostnameBacklinks(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - ns := mockNamesys{} ts, api, ctx := newTestServerAndNode(t, ns) t.Logf("test server url: %s", ts.URL) diff --git a/gateway/core/corehttp/mutex_profile.go b/gateway/core/corehttp/mutex_profile.go index db39a7bc9..f8d66e5ef 100644 --- a/gateway/core/corehttp/mutex_profile.go +++ b/gateway/core/corehttp/mutex_profile.go @@ -20,7 +20,7 @@ func MutexFractionOption(path string) ServeOption { } if err := r.ParseForm(); err != nil { w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(err.Error())) + _, _ = w.Write([]byte(err.Error())) return } @@ -33,7 +33,7 @@ func MutexFractionOption(path string) ServeOption { fr, err := strconv.Atoi(asfr) if err != nil { w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(err.Error())) + _, _ = w.Write([]byte(err.Error())) return } log.Infof("Setting MutexProfileFraction to %d", fr) diff --git a/gateway/core/corehttp/option_test.go b/gateway/core/corehttp/option_test.go index 22157618c..17fcefe09 100644 --- a/gateway/core/corehttp/option_test.go +++ b/gateway/core/corehttp/option_test.go @@ -52,7 +52,9 @@ func TestCheckVersionOption(t *testing.T) { if !tc.shouldHandle { t.Error("handler was called even though version didn't match") } else { - io.WriteString(w, "check!") + if _, err := io.WriteString(w, "check!"); err != nil { + t.Error(err) + } } })