Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve code quality #1064

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion auth/jwt/transport_test.go
Expand Up @@ -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(JWTTokenContextKey)
if token != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/kitgen/path_test.go
Expand Up @@ -40,7 +40,7 @@ func TestImportPathSadpath(t *testing.T) {
if actual != "" {
t.Errorf("Expected empty path, got %q", actual)
}
if strings.Index(err.Error(), expected) == -1 {
if !strings.Contains(err.Error(), expected) {
t.Errorf("Expected %q to include %q", err, expected)
}
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/kitgen/transform.go
Expand Up @@ -59,7 +59,7 @@ func importPath(targetDir, gopath string) (string, error) {
if err != nil {
continue
}
if strings.Index(res, "..") == -1 {
if !strings.Contains(res, "..") {
return res, nil
}
}
Expand Down
3 changes: 1 addition & 2 deletions log/sync_test.go
Expand Up @@ -58,8 +58,7 @@ func TestSwapLoggerConcurrency(t *testing.T) {
}

func TestSyncLoggerConcurrency(t *testing.T) {
var w io.Writer
w = &bytes.Buffer{}
var w io.Writer = &bytes.Buffer{}
logger := log.NewLogfmtLogger(w)
logger = log.NewSyncLogger(logger)
testConcurrency(t, logger, 10000)
Expand Down
2 changes: 1 addition & 1 deletion metrics/generic/generic.go
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions sd/etcd/client_test.go
@@ -1,11 +1,11 @@
package etcd

import (
"context"
"errors"
"reflect"
"testing"
"time"
"context"

etcd "go.etcd.io/etcd/client"
)
Expand Down Expand Up @@ -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:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This results in different behavior, does it not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't change the observed behavior (it'll still block until either one of the first two cases return something).

TBH I don't really understand why the for loop is necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if you have the default, you need the for, otherwise this is a one-and-done.

But it's still a terrible pattern, as it turns what could be a simple select into a hot loop?? Maybe an artifact from refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, yeah. @withshubh could you please remove the for loop as well?

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sd/zk/client_test.go
Expand Up @@ -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)
}

Expand Down
5 changes: 3 additions & 2 deletions transport/http/proto/proto_test.go
@@ -1,6 +1,7 @@
package proto

import (
"context"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down