From abd72ba989943f559721c242f51a94e33a2569a1 Mon Sep 17 00:00:00 2001 From: shubhendra Date: Thu, 25 Feb 2021 14:30:58 +0530 Subject: [PATCH 1/6] Fix unnecessary calls to Printf --- .deepsource.toml | 12 ++++++++++++ metrics/generic/generic.go | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .deepsource.toml diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 000000000..f6c0dd8fa --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,12 @@ +version = 1 + +test_patterns = ["**/*_test.go"] + +exclude_patterns = ["examples/**"] + +[[analyzers]] +name = "go" +enabled = true + + [analyzers.meta] + import_paths = ["github.com/go-kit/kit"] diff --git a/metrics/generic/generic.go b/metrics/generic/generic.go index b69334507..39216c04f 100644 --- a/metrics/generic/generic.go +++ b/metrics/generic/generic.go @@ -182,7 +182,7 @@ func (h *Histogram) LabelValues() []string { func (h *Histogram) Print(w io.Writer) { h.h.RLock() defer h.h.RUnlock() - fmt.Fprintf(w, h.h.String()) + fmt.Fprint(w, h.h.String()) } // safeHistogram exists as gohistogram.Histogram is not goroutine-safe. From 5550f4e5bf314ee7044ff5769d356beff7601ade Mon Sep 17 00:00:00 2001 From: shubhendra Date: Thu, 25 Feb 2021 14:30:58 +0530 Subject: [PATCH 2/6] Fix nil context being passed to function --- transport/http/proto/proto_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/transport/http/proto/proto_test.go b/transport/http/proto/proto_test.go index 2f1cd17b7..1cc27f6d7 100644 --- a/transport/http/proto/proto_test.go +++ b/transport/http/proto/proto_test.go @@ -1,6 +1,7 @@ package proto import ( + "context" "io/ioutil" "net/http" "net/http/httptest" @@ -14,7 +15,7 @@ func TestEncodeProtoRequest(t *testing.T) { r := httptest.NewRequest(http.MethodGet, "/cat", nil) - err := EncodeProtoRequest(nil, r, cat) + err := EncodeProtoRequest(context.TODO(), r, cat) if err != nil { t.Errorf("expected no encoding errors but got: %s", err) return @@ -51,7 +52,7 @@ func TestEncodeProtoResponse(t *testing.T) { wr := httptest.NewRecorder() - err := EncodeProtoResponse(nil, wr, cat) + err := EncodeProtoResponse(context.TODO(), wr, cat) if err != nil { t.Errorf("expected no encoding errors but got: %s", err) return From d53f8e6879552ca52f5e37b776fb9b89a0f59a30 Mon Sep 17 00:00:00 2001 From: shubhendra Date: Thu, 25 Feb 2021 14:30:59 +0530 Subject: [PATCH 3/6] Remove empty default in select --- sd/etcd/client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd/etcd/client_test.go b/sd/etcd/client_test.go index 93a7f4159..b464a99c6 100644 --- a/sd/etcd/client_test.go +++ b/sd/etcd/client_test.go @@ -135,7 +135,7 @@ func (fw *fakeWatcher) Next(context.Context) (*etcd.Response, error) { return nil, nil case <-fw.err: return nil, errors.New("error from underlying etcd watcher") - default: + } } } From 6e5c91d551071b19fbb629635df2990eba9f3e75 Mon Sep 17 00:00:00 2001 From: shubhendra Date: Thu, 25 Feb 2021 14:31:01 +0530 Subject: [PATCH 4/6] Replace `bytes.Compare` with `bytes.Equal` --- sd/zk/client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd/zk/client_test.go b/sd/zk/client_test.go index 96b25cc25..7ca097ad4 100644 --- a/sd/zk/client_test.go +++ b/sd/zk/client_test.go @@ -63,7 +63,7 @@ func TestNewClient(t *testing.T) { if want, have := sessionTimeout, clientImpl.sessionTimeout; want != have { t.Errorf("want %d, have %d", want, have) } - if want, have := payload, clientImpl.rootNodePayload; bytes.Compare(want[0], have[0]) != 0 || bytes.Compare(want[1], have[1]) != 0 { + if want, have := payload, clientImpl.rootNodePayload; !bytes.Equal(want[0], have[0]) || !bytes.Equal(want[1], have[1]) { t.Errorf("want %s, have %s", want, have) } From 5d96968aaa37128b28ce48776f225fe7c072ed98 Mon Sep 17 00:00:00 2001 From: shubhendra Date: Thu, 25 Feb 2021 14:31:02 +0530 Subject: [PATCH 5/6] Remove unnecessary use of `fmt.Sprintf` --- .deepsource.toml | 12 ------------ auth/jwt/transport_test.go | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 .deepsource.toml diff --git a/.deepsource.toml b/.deepsource.toml deleted file mode 100644 index f6c0dd8fa..000000000 --- a/.deepsource.toml +++ /dev/null @@ -1,12 +0,0 @@ -version = 1 - -test_patterns = ["**/*_test.go"] - -exclude_patterns = ["examples/**"] - -[[analyzers]] -name = "go" -enabled = true - - [analyzers.meta] - import_paths = ["github.com/go-kit/kit"] diff --git a/auth/jwt/transport_test.go b/auth/jwt/transport_test.go index 096c6ac31..91037ee3c 100644 --- a/auth/jwt/transport_test.go +++ b/auth/jwt/transport_test.go @@ -76,7 +76,7 @@ func TestGRPCToContext(t *testing.T) { } // Invalid Authorization header is passed - md["authorization"] = []string{fmt.Sprintf("%s", signedKey)} + md["authorization"] = []string{signedKey} ctx = reqFunc(context.Background(), md) token = ctx.Value(JWTContextKey) if token != nil { From 1c0d7c914b32d810cadf90371113c5b40f86e56a Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Tue, 20 Jul 2021 19:59:03 +0200 Subject: [PATCH 6/6] Remove unnecessary hot loop Signed-off-by: Mark Sagi-Kazar --- sd/etcd/client_test.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sd/etcd/client_test.go b/sd/etcd/client_test.go index b464a99c6..ee8fd5655 100644 --- a/sd/etcd/client_test.go +++ b/sd/etcd/client_test.go @@ -129,14 +129,12 @@ type fakeWatcher struct { // When an event occurs it just return nil response and error. // When an error occur it return a non nil error. func (fw *fakeWatcher) Next(context.Context) (*etcd.Response, error) { - for { - select { - case <-fw.event: - return nil, nil - case <-fw.err: - return nil, errors.New("error from underlying etcd watcher") + select { + case <-fw.event: + return nil, nil + case <-fw.err: + return nil, errors.New("error from underlying etcd watcher") - } } }