From 8abf7df5e134086d1b0ede48d94cfe4787e41616 Mon Sep 17 00:00:00 2001 From: CodeLingo Bot Date: Tue, 5 Feb 2019 05:52:45 +0000 Subject: [PATCH 1/2] Fix error formatting based on best practices from Code Review Comments Signed-off-by: CodeLingo Bot --- balancer/grpclb/grpclb_test.go | 4 ++-- balancer/roundrobin/roundrobin_test.go | 2 +- balancer_switching_test.go | 4 ++-- picker_wrapper_test.go | 2 +- test/bufconn/bufconn.go | 2 +- test/channelz_test.go | 6 +++--- test/healthcheck_test.go | 14 +++++++------- test/rawConnWrapper.go | 2 +- test/retry_test.go | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/balancer/grpclb/grpclb_test.go b/balancer/grpclb/grpclb_test.go index 0cada90c74f2..56c0bb3246ad 100644 --- a/balancer/grpclb/grpclb_test.go +++ b/balancer/grpclb/grpclb_test.go @@ -310,7 +310,7 @@ func newLoadBalancer(numberOfBackends int) (tss *testServers, cleanup func(), er // Start a backend. beLis, e := net.Listen("tcp", "localhost:0") if e != nil { - err = fmt.Errorf("Failed to listen %v", err) + err = fmt.Errorf("failed to listen %v", err) return } beIPs = append(beIPs, beLis.Addr().(*net.TCPAddr).IP) @@ -323,7 +323,7 @@ func newLoadBalancer(numberOfBackends int) (tss *testServers, cleanup func(), er // Start a load balancer. lbLis, err := net.Listen("tcp", "localhost:0") if err != nil { - err = fmt.Errorf("Failed to create the listener for the load balancer %v", err) + err = fmt.Errorf("failed to create the listener for the load balancer %v", err) return } lbCreds := &serverNameCheckCreds{ diff --git a/balancer/roundrobin/roundrobin_test.go b/balancer/roundrobin/roundrobin_test.go index d56baef12408..94970062ae30 100644 --- a/balancer/roundrobin/roundrobin_test.go +++ b/balancer/roundrobin/roundrobin_test.go @@ -72,7 +72,7 @@ func startTestServers(count int) (_ *test, err error) { for i := 0; i < count; i++ { lis, err := net.Listen("tcp", "localhost:0") if err != nil { - return nil, fmt.Errorf("Failed to listen %v", err) + return nil, fmt.Errorf("failed to listen %v", err) } s := grpc.NewServer() diff --git a/balancer_switching_test.go b/balancer_switching_test.go index 779d053e0517..9006c0d35f4d 100644 --- a/balancer_switching_test.go +++ b/balancer_switching_test.go @@ -86,7 +86,7 @@ func checkPickFirst(cc *ClientConn, servers []*server) error { for i := 0; i < 3; i++ { err = cc.Invoke(context.Background(), "/foo/bar", &req, &reply) if errorDesc(err) != servers[0].port { - return fmt.Errorf("Index %d: want peer %v, got peer %v", i, servers[0].port, err) + return fmt.Errorf("index %d: want peer %v, got peer %v", i, servers[0].port, err) } } return nil @@ -122,7 +122,7 @@ func checkRoundRobin(cc *ClientConn, servers []*server) error { for i := 0; i < 3*serverCount; i++ { err = cc.Invoke(context.Background(), "/foo/bar", &req, &reply) if errorDesc(err) != servers[i%serverCount].port { - return fmt.Errorf("Index %d: want peer %v, got peer %v", i, servers[i%serverCount].port, err) + return fmt.Errorf("index %d: want peer %v, got peer %v", i, servers[i%serverCount].port, err) } } return nil diff --git a/picker_wrapper_test.go b/picker_wrapper_test.go index 7228b3af2802..d6e8c36361be 100644 --- a/picker_wrapper_test.go +++ b/picker_wrapper_test.go @@ -56,7 +56,7 @@ type testingPicker struct { func (p *testingPicker) Pick(ctx context.Context, opts balancer.PickOptions) (balancer.SubConn, func(balancer.DoneInfo), error) { if atomic.AddInt64(&p.maxCalled, -1) < 0 { - return nil, nil, fmt.Errorf("Pick called to many times (> goroutineCount)") + return nil, nil, fmt.Errorf("pick called to many times (> goroutineCount)") } if p.err != nil { return nil, nil, p.err diff --git a/test/bufconn/bufconn.go b/test/bufconn/bufconn.go index bdb5d812e404..60ae770f54e2 100644 --- a/test/bufconn/bufconn.go +++ b/test/bufconn/bufconn.go @@ -37,7 +37,7 @@ type Listener struct { done chan struct{} } -var errClosed = fmt.Errorf("Closed") +var errClosed = fmt.Errorf("closed") // Listen returns a Listener that can only be contacted by its own Dialers and // creates buffered connections between the two. diff --git a/test/channelz_test.go b/test/channelz_test.go index 6e4a3eaa7e76..b03f00771a89 100644 --- a/test/channelz_test.go +++ b/test/channelz_test.go @@ -355,7 +355,7 @@ func (s) TestCZServerSocketRegistrationAndDeletion(t *testing.T) { ns, end := channelz.GetServerSockets(ss[0].ID, startID, c.max) if int64(len(ns)) != c.length || end != c.end { - return false, fmt.Errorf("GetServerSockets(%d) = %+v (len of which: %d), end: %+v, want len(GetServerSockets(%d)) = %d, end: %+v", c.start, ns, len(ns), end, c.start, c.length, c.end) + return false, fmt.Errorf("getServerSockets(%d) = %+v (len of which: %d), end: %+v, want len(GetServerSockets(%d)) = %d, end: %+v", c.start, ns, len(ns), end, c.start, c.length, c.end) } svrID = ss[0].ID @@ -1320,14 +1320,14 @@ func (s) TestCZSocketGetSecurityValueTLS(t *testing.T) { return false, fmt.Errorf("the SocketData.Security is of type: %T, want: *credentials.TLSChannelzSecurityValue", skt.SocketData.Security) } if !reflect.DeepEqual(securityVal.RemoteCertificate, cert.Certificate[0]) { - return false, fmt.Errorf("SocketData.Security.RemoteCertificate got: %v, want: %v", securityVal.RemoteCertificate, cert.Certificate[0]) + return false, fmt.Errorf("socketData.Security.RemoteCertificate got: %v, want: %v", securityVal.RemoteCertificate, cert.Certificate[0]) } for _, v := range cipherSuites { if v == securityVal.StandardName { return true, nil } } - return false, fmt.Errorf("SocketData.Security.StandardName got: %v, want it to be one of %v ", securityVal.StandardName, cipherSuites) + return false, fmt.Errorf("socketData.Security.StandardName got: %v, want it to be one of %v", securityVal.StandardName, cipherSuites) }); err != nil { t.Fatal(err) } diff --git a/test/healthcheck_test.go b/test/healthcheck_test.go index 82133b0d929a..960efbe4ab01 100644 --- a/test/healthcheck_test.go +++ b/test/healthcheck_test.go @@ -312,7 +312,7 @@ func (s) TestHealthCheckWithGoAway(t *testing.T) { // make some rpcs to make sure connection is working. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -403,7 +403,7 @@ func (s) TestHealthCheckWithConnClose(t *testing.T) { // make some rpcs to make sure connection is working. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -463,7 +463,7 @@ func (s) TestHealthCheckWithAddrConnDrain(t *testing.T) { // make some rpcs to make sure connection is working. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -553,7 +553,7 @@ func (s) TestHealthCheckWithClientConnClose(t *testing.T) { // make some rpcs to make sure connection is working. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -752,7 +752,7 @@ func testHealthCheckDisableWithDialOption(t *testing.T, addr string) { // send some rpcs to make sure transport has been created and is ready for use. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -790,7 +790,7 @@ func testHealthCheckDisableWithBalancer(t *testing.T, addr string) { // send some rpcs to make sure transport has been created and is ready for use. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -823,7 +823,7 @@ func testHealthCheckDisableWithServiceConfig(t *testing.T, addr string) { // send some rpcs to make sure transport has been created and is ready for use. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { diff --git a/test/rawConnWrapper.go b/test/rawConnWrapper.go index 5d991cf013ac..f1a1f2442231 100644 --- a/test/rawConnWrapper.go +++ b/test/rawConnWrapper.go @@ -222,7 +222,7 @@ func (rcw *rawConnWrapper) wantAnyFrame() (http2.Frame, error) { func (rcw *rawConnWrapper) encodeHeaderField(k, v string) error { err := rcw.hpackEnc.WriteField(hpack.HeaderField{Name: k, Value: v}) if err != nil { - return fmt.Errorf("HPACK encoding error for %q/%q: %v", k, v, err) + return fmt.Errorf("hPACK encoding error for %q/%q: %v", k, v, err) } return nil } diff --git a/test/retry_test.go b/test/retry_test.go index 8468e70536ba..10b3c6468df0 100644 --- a/test/retry_test.go +++ b/test/retry_test.go @@ -386,7 +386,7 @@ func (s) TestRetryStreaming(t *testing.T) { cCheckElapsed := func(d time.Duration) clientOp { return func(_ testpb.TestService_FullDuplexCallClient) error { if elapsed := time.Since(curTime); elapsed < d { - return fmt.Errorf("Elapsed time: %v; want >= %v", elapsed, d) + return fmt.Errorf("elapsed time: %v; want >= %v", elapsed, d) } return nil } From 9b37072fb06fa685e3d9a914c5932212ab770eae Mon Sep 17 00:00:00 2001 From: CodeLingo Bot Date: Thu, 7 Feb 2019 15:06:01 +1300 Subject: [PATCH 2/2] Fix error formatting based on best practices from Code Review Comments Signed-off-by: CodeLingo Bot --- test/channelz_test.go | 6 +++--- test/healthcheck_test.go | 14 +++++++------- test/rawConnWrapper.go | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/channelz_test.go b/test/channelz_test.go index b03f00771a89..d31f459120e9 100644 --- a/test/channelz_test.go +++ b/test/channelz_test.go @@ -355,7 +355,7 @@ func (s) TestCZServerSocketRegistrationAndDeletion(t *testing.T) { ns, end := channelz.GetServerSockets(ss[0].ID, startID, c.max) if int64(len(ns)) != c.length || end != c.end { - return false, fmt.Errorf("getServerSockets(%d) = %+v (len of which: %d), end: %+v, want len(GetServerSockets(%d)) = %d, end: %+v", c.start, ns, len(ns), end, c.start, c.length, c.end) + return false, fmt.Errorf("GetServerSockets(%d) = %+v (len of which: %d), end: %+v, want len(GetServerSockets(%d)) = %d, end: %+v", c.start, ns, len(ns), end, c.start, c.length, c.end) } svrID = ss[0].ID @@ -1320,14 +1320,14 @@ func (s) TestCZSocketGetSecurityValueTLS(t *testing.T) { return false, fmt.Errorf("the SocketData.Security is of type: %T, want: *credentials.TLSChannelzSecurityValue", skt.SocketData.Security) } if !reflect.DeepEqual(securityVal.RemoteCertificate, cert.Certificate[0]) { - return false, fmt.Errorf("socketData.Security.RemoteCertificate got: %v, want: %v", securityVal.RemoteCertificate, cert.Certificate[0]) + return false, fmt.Errorf("SocketData.Security.RemoteCertificate got: %v, want: %v", securityVal.RemoteCertificate, cert.Certificate[0]) } for _, v := range cipherSuites { if v == securityVal.StandardName { return true, nil } } - return false, fmt.Errorf("socketData.Security.StandardName got: %v, want it to be one of %v", securityVal.StandardName, cipherSuites) + return false, fmt.Errorf("SocketData.Security.StandardName got: %v, want it to be one of %v", securityVal.StandardName, cipherSuites) }); err != nil { t.Fatal(err) } diff --git a/test/healthcheck_test.go b/test/healthcheck_test.go index 960efbe4ab01..82133b0d929a 100644 --- a/test/healthcheck_test.go +++ b/test/healthcheck_test.go @@ -312,7 +312,7 @@ func (s) TestHealthCheckWithGoAway(t *testing.T) { // make some rpcs to make sure connection is working. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -403,7 +403,7 @@ func (s) TestHealthCheckWithConnClose(t *testing.T) { // make some rpcs to make sure connection is working. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -463,7 +463,7 @@ func (s) TestHealthCheckWithAddrConnDrain(t *testing.T) { // make some rpcs to make sure connection is working. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -553,7 +553,7 @@ func (s) TestHealthCheckWithClientConnClose(t *testing.T) { // make some rpcs to make sure connection is working. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -752,7 +752,7 @@ func testHealthCheckDisableWithDialOption(t *testing.T, addr string) { // send some rpcs to make sure transport has been created and is ready for use. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -790,7 +790,7 @@ func testHealthCheckDisableWithBalancer(t *testing.T, addr string) { // send some rpcs to make sure transport has been created and is ready for use. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { @@ -823,7 +823,7 @@ func testHealthCheckDisableWithServiceConfig(t *testing.T, addr string) { // send some rpcs to make sure transport has been created and is ready for use. if err := verifyResultWithDelay(func() (bool, error) { if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); err != nil { - return false, fmt.Errorf("testService/EmptyCall(_, _) = _, %v, want _, ", err) + return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, ", err) } return true, nil }); err != nil { diff --git a/test/rawConnWrapper.go b/test/rawConnWrapper.go index f1a1f2442231..5d991cf013ac 100644 --- a/test/rawConnWrapper.go +++ b/test/rawConnWrapper.go @@ -222,7 +222,7 @@ func (rcw *rawConnWrapper) wantAnyFrame() (http2.Frame, error) { func (rcw *rawConnWrapper) encodeHeaderField(k, v string) error { err := rcw.hpackEnc.WriteField(hpack.HeaderField{Name: k, Value: v}) if err != nil { - return fmt.Errorf("hPACK encoding error for %q/%q: %v", k, v, err) + return fmt.Errorf("HPACK encoding error for %q/%q: %v", k, v, err) } return nil }