diff --git a/consul/acl_test.go b/consul/acl_test.go index baf7033cf9..2e1d30c915 100644 --- a/consul/acl_test.go +++ b/consul/acl_test.go @@ -1,7 +1,6 @@ package consul import ( - "errors" "fmt" "os" "reflect" @@ -234,7 +233,7 @@ func TestACL_NonAuthority_NotFound(t *testing.T) { if err := testrpc.WaitForResult(func() (bool, error) { p1, _ := s1.numPeers() - return p1 == 2, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 2, fmt.Errorf("%d", p1) }); err != nil { t.Fatal(err) } @@ -286,7 +285,7 @@ func TestACL_NonAuthority_Found(t *testing.T) { if err := testrpc.WaitForResult(func() (bool, error) { p1, _ := s1.numPeers() - return p1 == 2, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 2, fmt.Errorf("%d", p1) }); err != nil { t.Fatal(err) } @@ -362,7 +361,7 @@ func TestACL_NonAuthority_Management(t *testing.T) { if err := testrpc.WaitForResult(func() (bool, error) { p1, _ := s1.numPeers() - return p1 == 2, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 2, fmt.Errorf("%d", p1) }); err != nil { t.Fatal(err) } @@ -419,7 +418,7 @@ func TestACL_DownPolicy_Deny(t *testing.T) { if err := testrpc.WaitForResult(func() (bool, error) { p1, _ := s1.numPeers() - return p1 == 2, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 2, fmt.Errorf("%d", p1) }); err != nil { t.Fatal(err) } @@ -493,7 +492,7 @@ func TestACL_DownPolicy_Allow(t *testing.T) { if err := testrpc.WaitForResult(func() (bool, error) { p1, _ := s1.numPeers() - return p1 == 2, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 2, fmt.Errorf("%d", p1) }); err != nil { t.Fatal(err) } @@ -569,7 +568,7 @@ func TestACL_DownPolicy_ExtendCache(t *testing.T) { if err := testrpc.WaitForResult(func() (bool, error) { p1, _ := s1.numPeers() - return p1 == 2, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 2, fmt.Errorf("%d", p1) }); err != nil { t.Fatal(err) } diff --git a/consul/fsm.go b/consul/fsm.go index c44d0dfafb..214ab71d86 100644 --- a/consul/fsm.go +++ b/consul/fsm.go @@ -1,7 +1,6 @@ package consul import ( - "errors" "fmt" "io" "log" @@ -204,7 +203,7 @@ func (c *consulFSM) applyKVSOperation(buf []byte, index uint64) interface{} { return act } default: - err := errors.New(fmt.Sprintf("Invalid KVS operation '%s'", req.Op)) + err := fmt.Errorf("Invalid KVS operation '%s'", req.Op) c.logger.Printf("[WARN] consul.fsm: %v", err) return err } diff --git a/consul/leader_test.go b/consul/leader_test.go index 82479e2000..414831302b 100644 --- a/consul/leader_test.go +++ b/consul/leader_test.go @@ -496,7 +496,7 @@ func TestLeader_LeftServer(t *testing.T) { for _, s := range servers[1:] { peers, _ := s.numPeers() - return peers == 2, errors.New(fmt.Sprintf("%d", peers)) + return peers == 2, fmt.Errorf("%d", peers) } return true, nil @@ -561,7 +561,7 @@ func TestLeader_LeftLeader(t *testing.T) { remain = s if err := testrpc.WaitForResult(func() (bool, error) { peers, _ := s.numPeers() - return peers == 2, errors.New(fmt.Sprintf("%d", peers)) + return peers == 2, fmt.Errorf("%d", peers) }); err != nil { t.Fatal("should have 2 peers") } diff --git a/consul/server_test.go b/consul/server_test.go index 55215e1f3d..ecdb087e5c 100644 --- a/consul/server_test.go +++ b/consul/server_test.go @@ -1,7 +1,6 @@ package consul import ( - "errors" "fmt" "io/ioutil" "net" @@ -378,14 +377,14 @@ func TestServer_LeaveLeader(t *testing.T) { if err := testrpc.WaitForResult(func() (bool, error) { p1, _ = s1.numPeers() - return p1 == 2, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 2, fmt.Errorf("%d", p1) }); err != nil { t.Fatalf("should have 2 peers %s", err) } if err := testrpc.WaitForResult(func() (bool, error) { p2, _ = s2.numPeers() - return p2 == 2, errors.New(fmt.Sprintf("%d", p1)) + return p2 == 2, fmt.Errorf("%d", p1) }); err != nil { t.Fatalf("should have 2 peers %s", err) } @@ -433,14 +432,14 @@ func TestServer_Leave(t *testing.T) { if err := testrpc.WaitForResult(func() (bool, error) { p1, _ = s1.numPeers() - return p1 == 2, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 2, fmt.Errorf("%d", p1) }); err != nil { t.Fatalf("should have 2 peers %s", err) } if err := testrpc.WaitForResult(func() (bool, error) { p2, _ = s2.numPeers() - return p2 == 2, errors.New(fmt.Sprintf("%d", p1)) + return p2 == 2, fmt.Errorf("%d", p1) }); err != nil { t.Fatalf("should have 2 peers %s", err) } @@ -570,14 +569,14 @@ func TestServer_Expect(t *testing.T) { // Should have no peers yet since the bootstrap didn't occur. if err := testrpc.WaitForResult(func() (bool, error) { p1, _ = s1.numPeers() - return p1 == 0, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 0, fmt.Errorf("%d", p1) }); err != nil { t.Fatalf("should have 0 peers %s", err) } if err := testrpc.WaitForResult(func() (bool, error) { p2, _ = s2.numPeers() - return p2 == 0, errors.New(fmt.Sprintf("%d", p2)) + return p2 == 0, fmt.Errorf("%d", p2) }); err != nil { t.Fatalf("should have 0 peers %s", err) } @@ -592,21 +591,21 @@ func TestServer_Expect(t *testing.T) { // Now we have three servers so we should bootstrap. if err := testrpc.WaitForResult(func() (bool, error) { p1, _ = s1.numPeers() - return p1 == 3, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 3, fmt.Errorf("%d", p1) }); err != nil { t.Fatalf("should have 3 peers %s", err) } if err := testrpc.WaitForResult(func() (bool, error) { p2, _ = s2.numPeers() - return p2 == 3, errors.New(fmt.Sprintf("%d", p2)) + return p2 == 3, fmt.Errorf("%d", p2) }); err != nil { t.Fatalf("should have 3 peers %s", err) } if err := testrpc.WaitForResult(func() (bool, error) { p3, _ = s3.numPeers() - return p3 == 3, errors.New(fmt.Sprintf("%d", p3)) + return p3 == 3, fmt.Errorf("%d", p3) }); err != nil { t.Fatalf("should have 3 peers %s", err) } @@ -623,7 +622,7 @@ func TestServer_Expect(t *testing.T) { var p4 int if err := testrpc.WaitForResult(func() (bool, error) { p4, _ = s4.numPeers() - return p4 == 4, errors.New(fmt.Sprintf("%d", p4)) + return p4 == 4, fmt.Errorf("%d", p4) }); err != nil { t.Fatalf("should have 4 peers %s", err) } @@ -666,14 +665,14 @@ func TestServer_BadExpect(t *testing.T) { // should have no peers yet if err := testrpc.WaitForResult(func() (bool, error) { p1, _ = s1.numPeers() - return p1 == 0, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 0, fmt.Errorf("%d", p1) }); err != nil { t.Fatalf("should have 0 peers %s", err) } if err := testrpc.WaitForResult(func() (bool, error) { p2, _ = s2.numPeers() - return p2 == 0, errors.New(fmt.Sprintf("%d", p2)) + return p2 == 0, fmt.Errorf("%d", p2) }); err != nil { t.Fatalf("should have 0 peers %s", err) } @@ -688,21 +687,21 @@ func TestServer_BadExpect(t *testing.T) { // should still have no peers (because s2 is in expect=2 mode) if err := testrpc.WaitForResult(func() (bool, error) { p1, _ = s1.numPeers() - return p1 == 0, errors.New(fmt.Sprintf("%d", p1)) + return p1 == 0, fmt.Errorf("%d", p1) }); err != nil { t.Fatalf("should have 0 peers %s", err) } if err := testrpc.WaitForResult(func() (bool, error) { p2, _ = s2.numPeers() - return p2 == 0, errors.New(fmt.Sprintf("%d", p2)) + return p2 == 0, fmt.Errorf("%d", p2) }); err != nil { t.Fatalf("should have 0 peers %s", err) } if err := testrpc.WaitForResult(func() (bool, error) { p3, _ = s3.numPeers() - return p3 == 0, errors.New(fmt.Sprintf("%d", p3)) + return p3 == 0, fmt.Errorf("%d", p3) }); err != nil { t.Fatalf("should have 0 peers %s", err) }