golint: Use fmt.Errorf(...)

Replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)

    gofmt -w -r 'errors.New(fmt.Sprintf(a, b)) -> fmt.Errorf(a, b)' *.go
This commit is contained in:
Frank Schroeder 2017-04-20 11:49:34 -07:00 committed by Frank Schröder
parent 8bb7792799
commit 5f34d766b8
4 changed files with 24 additions and 27 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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")
}

View File

@ -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)
}