Skip to content

Commit

Permalink
all: don't convert byte slice to string when using verb %s
Browse files Browse the repository at this point in the history
This is unnecessary, as the documentation for 'go doc fmt' says:
%s the uninterpreted bytes of the string or slice

Signed-off-by: Jes Cok <[email protected]>
  • Loading branch information
callthingsoff committed Apr 25, 2024
1 parent 3ecb70d commit dafadd1
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion client/pkg/transport/timeout_transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ func TestNewTimeoutTransport(t *testing.T) {
}

if bytes.Equal(addr0, addr1) {
t.Errorf("addr0 = %s addr1= %s, want not equal", string(addr0), string(addr1))
t.Errorf("addr0 = %s addr1= %s, want not equal", addr0, addr1)
}
}
4 changes: 2 additions & 2 deletions etcdctl/ctlv3/command/printer_simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (s *simplePrinter) RoleGet(role string, r v3.AuthRoleGetResponse) {
for _, perm := range r.Perm {
if perm.PermType == v3.PermRead || perm.PermType == v3.PermReadWrite {
if len(perm.RangeEnd) == 0 {
fmt.Printf("\t%s\n", string(perm.Key))
fmt.Printf("\t%s\n", perm.Key)
} else {
printRange((*v3.Permission)(perm))
}
Expand All @@ -233,7 +233,7 @@ func (s *simplePrinter) RoleGet(role string, r v3.AuthRoleGetResponse) {
for _, perm := range r.Perm {
if perm.PermType == v3.PermWrite || perm.PermType == v3.PermReadWrite {
if len(perm.RangeEnd) == 0 {
fmt.Printf("\t%s\n", string(perm.Key))
fmt.Printf("\t%s\n", perm.Key)
} else {
printRange((*v3.Permission)(perm))
}
Expand Down
6 changes: 3 additions & 3 deletions etcdutl/snapshot/v3_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ func (s *v3Manager) Status(dbPath string) (ds Status, err error) {
for next, _ := c.First(); next != nil; next, _ = c.Next() {
b := tx.Bucket(next)
if b == nil {
return fmt.Errorf("cannot get hash of bucket %s", string(next))
return fmt.Errorf("cannot get hash of bucket %s", next)
}
if _, err = h.Write(next); err != nil {
return fmt.Errorf("cannot write bucket %s : %v", string(next), err)
return fmt.Errorf("cannot write bucket %s : %v", next, err)
}
iskeyb := (string(next) == "key")
if err = b.ForEach(func(k, v []byte) error {
Expand All @@ -163,7 +163,7 @@ func (s *v3Manager) Status(dbPath string) (ds Status, err error) {
ds.TotalKey++
return nil
}); err != nil {
return fmt.Errorf("cannot write bucket %s : %v", string(next), err)
return fmt.Errorf("cannot write bucket %s : %v", next, err)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/api/etcdhttp/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func TestNewPeerHandlerOnMembersPromotePrefix(t *testing.T) {
t.Fatalf("#%d: code = %d, want %d", i, resp.StatusCode, tt.wcode)
}
if tt.checkBody && strings.Contains(string(body), tt.wKeyWords) {
t.Errorf("#%d: body: %s, want body to contain keywords: %s", i, string(body), tt.wKeyWords)
t.Errorf("#%d: body: %s, want body to contain keywords: %s", i, body, tt.wKeyWords)
}
}
}
4 changes: 2 additions & 2 deletions server/etcdserver/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ func promoteMemberHTTP(ctx context.Context, url string, id uint64, peerRt http.R
if strings.Contains(string(b), membership.ErrMemberNotLearner.Error()) {
return nil, membership.ErrMemberNotLearner
}
return nil, fmt.Errorf("member promote: unknown error(%s)", string(b))
return nil, fmt.Errorf("member promote: unknown error(%s)", b)
}
if resp.StatusCode == http.StatusNotFound {
return nil, membership.ErrIDNotFound
}

if resp.StatusCode != http.StatusOK { // all other types of errors
return nil, fmt.Errorf("member promote: unknown error(%s)", string(b))
return nil, fmt.Errorf("member promote: unknown error(%s)", b)
}

var membs []*membership.Member
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/corrupt.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ func HashByRev(ctx context.Context, cid types.ID, cc *http.Client, url string, r
}
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unknown error: %s", string(b))
return nil, fmt.Errorf("unknown error: %s", b)
}

hashResp := &pb.HashKVResponse{}
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/corrupt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ func TestHashKVHandler(t *testing.T) {
}
if resp.StatusCode != http.StatusOK {
if !strings.Contains(string(body), tt.wKeyWords) {
t.Errorf("#%d: body: %s, want body to contain keywords: %s", i, string(body), tt.wKeyWords)
t.Errorf("#%d: body: %s, want body to contain keywords: %s", i, body, tt.wKeyWords)
}
return
}
Expand Down
4 changes: 2 additions & 2 deletions server/lease/leasehttp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ func RenewHTTP(ctx context.Context, id lease.LeaseID, url string, rt http.RoundT
}

if resp.StatusCode != http.StatusOK {
return -1, fmt.Errorf("lease: unknown error(%s)", string(b))
return -1, fmt.Errorf("lease: unknown error(%s)", b)
}

lresp := &pb.LeaseKeepAliveResponse{}
if err := lresp.Unmarshal(b); err != nil {
return -1, fmt.Errorf(`lease: %v. data = "%s"`, err, string(b))
return -1, fmt.Errorf(`lease: %v. data = "%s"`, err, b)
}
if lresp.ID != int64(id) {
return -1, fmt.Errorf("lease: renew id mismatch")
Expand Down
4 changes: 2 additions & 2 deletions server/storage/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func (b *backend) Hash(ignores func(bucketName, keyName []byte) bool) (uint32, e
for next, _ := c.First(); next != nil; next, _ = c.Next() {
b := tx.Bucket(next)
if b == nil {
return fmt.Errorf("cannot get hash of bucket %s", string(next))
return fmt.Errorf("cannot get hash of bucket %s", next)
}
h.Write(next)
b.ForEach(func(k, v []byte) error {
Expand Down Expand Up @@ -598,7 +598,7 @@ func defragdb(odb, tmpdb *bolt.DB, limit int) error {
for next, _ := c.First(); next != nil; next, _ = c.Next() {
b := tx.Bucket(next)
if b == nil {
return fmt.Errorf("backend: cannot defrag bucket %s", string(next))
return fmt.Errorf("backend: cannot defrag bucket %s", next)
}

tmpb, berr := tmptx.CreateBucketIfNotExists(next)
Expand Down
2 changes: 1 addition & 1 deletion server/storage/backend/batch_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestBatchTxPut(t *testing.T) {
_, gv := tx.UnsafeRange(schema.Test, []byte("foo"), nil, 0)
tx.Unlock()
if !reflect.DeepEqual(gv[0], v) {
t.Errorf("v = %s, want %s", string(gv[0]), string(v))
t.Errorf("v = %s, want %s", gv[0], v)
}
tx.Commit()
}
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/clientv3/naming/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ func testEtcdGRPCResolver(t *testing.T, lbPolicy string) {
t.Logf("Last response: %v", string(lastResponse))
if lbPolicy == "pick_first" {
if string(lastResponse) != "3500" {
t.Fatalf("unexpected total responses from foo: %s", string(lastResponse))
t.Fatalf("unexpected total responses from foo: %s", lastResponse)
}
}

// If the load balancing policy is round robin we should see roughly half total requests served by each server
if lbPolicy == "round_robin" {
responses, err := strconv.Atoi(string(lastResponse))
if err != nil {
t.Fatalf("couldn't convert to int: %s", string(lastResponse))
t.Fatalf("couldn't convert to int: %s", lastResponse)
}

// Allow 25% tolerance as round robin is not perfect and we don't want the test to flake
expected := float64(totalRequests) * 0.5
assert.InEpsilon(t, expected, float64(responses), 0.25, "unexpected total responses from foo: %s", string(lastResponse))
assert.InEpsilon(t, expected, float64(responses), 0.25, "unexpected total responses from foo: %s", lastResponse)
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/snapshot/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ func TestSnapshotV3RestoreMultiMemberAdd(t *testing.T) {
}
for i := range gresp.Kvs {
if string(gresp.Kvs[i].Key) != kvs[i].k {
t.Fatalf("#%d: key expected %s, got %s", i, kvs[i].k, string(gresp.Kvs[i].Key))
t.Fatalf("#%d: key expected %s, got %s", i, kvs[i].k, gresp.Kvs[i].Key)
}
if string(gresp.Kvs[i].Value) != kvs[i].v {
t.Fatalf("#%d: value expected %s, got %s", i, kvs[i].v, string(gresp.Kvs[i].Value))
t.Fatalf("#%d: value expected %s, got %s", i, kvs[i].v, gresp.Kvs[i].Value)
}
}
}
4 changes: 2 additions & 2 deletions tests/integration/snapshot/v3_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestSnapshotV3RestoreSingle(t *testing.T) {
t.Fatal(err)
}
if string(gresp.Kvs[0].Value) != kvs[i].v {
t.Fatalf("#%d: value expected %s, got %s", i, kvs[i].v, string(gresp.Kvs[0].Value))
t.Fatalf("#%d: value expected %s, got %s", i, kvs[i].v, gresp.Kvs[0].Value)
}
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestSnapshotV3RestoreMulti(t *testing.T) {
t.Fatal(err)
}
if string(gresp.Kvs[0].Value) != kvs[i].v {
t.Fatalf("#%d: value expected %s, got %s", i, kvs[i].v, string(gresp.Kvs[0].Value))
t.Fatalf("#%d: value expected %s, got %s", i, kvs[i].v, gresp.Kvs[0].Value)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/v3_failover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func getWithRetries(t *testing.T, cli *clientv3.Client, key, val string, retryCo
t.Fatalf("Expected 1 key, got %d", len(resp.Kvs))
}
if !bytes.Equal([]byte(val), resp.Kvs[0].Value) {
t.Fatalf("Unexpected value, expected: %s, got: %s", val, string(resp.Kvs[0].Value))
t.Fatalf("Unexpected value, expected: %s, got: %s", val, resp.Kvs[0].Value)
}
return nil
}()
Expand Down

0 comments on commit dafadd1

Please sign in to comment.