Skip to content

Commit 34cc553

Browse files
committed
chore: use bytes.Equal instead
1 parent b3fbe7e commit 34cc553

7 files changed

+10
-10
lines changed

Diff for: internal/raft/file_snapshot.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func (f *FileSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error
303303

304304
// Verify the hash
305305
computed := stateHash.Sum(nil)
306-
if bytes.Compare(meta.CRC, computed) != 0 {
306+
if !bytes.Equal(meta.CRC, computed) {
307307
f.logger.Printf("[ERR] snapshot: CRC checksum failed (stored: %v computed: %v)",
308308
meta.CRC, computed)
309309
fh.Close()

Diff for: internal/raft/file_snapshot_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func TestFileSS_CreateSnapshot(t *testing.T) {
133133
if latest.Term != 3 {
134134
t.Fatalf("bad snapshot: %v", *latest)
135135
}
136-
if bytes.Compare(latest.Peers, peers) != 0 {
136+
if !bytes.Equal(latest.Peers, peers) {
137137
t.Fatalf("bad snapshot: %v", *latest)
138138
}
139139
if latest.Size != 13 {
@@ -156,7 +156,7 @@ func TestFileSS_CreateSnapshot(t *testing.T) {
156156
}
157157

158158
// Ensure a match
159-
if bytes.Compare(buf.Bytes(), []byte("first\nsecond\n")) != 0 {
159+
if !bytes.Equal(buf.Bytes(), []byte("first\nsecond\n")) {
160160
t.Fatalf("content mismatch")
161161
}
162162
}

Diff for: internal/raft/integ_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ CHECK:
146146
}
147147
for idx, log := range first.fsm.logs {
148148
other := env.fsm.logs[idx]
149-
if bytes.Compare(log, other) != 0 {
149+
if !bytes.Equal(log, other) {
150150
err = fmt.Errorf("log %d mismatch %v %v", idx, log, other)
151151
goto ERR
152152
}

Diff for: internal/raft/net_transport_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func TestNetworkTransport_InstallSnapshot(t *testing.T) {
312312
rpc.Reader.Read(buf)
313313

314314
// Compare
315-
if bytes.Compare(buf, []byte("0123456789")) != 0 {
315+
if !bytes.Equal(buf, []byte("0123456789")) {
316316
t.Fatalf("bad buf %v", buf)
317317
}
318318

Diff for: internal/raft/raft.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ func (r *Raft) requestVote(rpc RPC, req *RequestVoteRequest) {
14851485
// Check if we've voted in this election before
14861486
if lastVoteTerm == req.Term && lastVoteCandBytes != nil {
14871487
r.logger.Printf("[INFO] raft: Duplicate RequestVote for same term: %d", req.Term)
1488-
if bytes.Compare(lastVoteCandBytes, req.Candidate) == 0 {
1488+
if bytes.Equal(lastVoteCandBytes, req.Candidate) {
14891489
r.logger.Printf("[WARN] raft: Duplicate RequestVote from candidate: %s", req.Candidate)
14901490
resp.Granted = true
14911491
}

Diff for: internal/raft/raft_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ CHECK:
464464
}
465465

466466
for idx := 0; idx < len(first.logs); idx++ {
467-
if bytes.Compare(first.logs[idx], fsm.logs[idx]) != 0 {
467+
if !bytes.Equal(first.logs[idx], fsm.logs[idx]) {
468468
fsm.Unlock()
469469
if time.Now().After(limit) {
470470
c.FailNowf("[ERR] FSM log mismatch at index %d", idx)
@@ -775,10 +775,10 @@ func TestRaft_LeaderFail(t *testing.T) {
775775
if len(fsm.logs) != 2 {
776776
c.FailNowf("[ERR] did not apply both to FSM! %v", fsm.logs)
777777
}
778-
if bytes.Compare(fsm.logs[0], []byte("test")) != 0 {
778+
if !bytes.Equal(fsm.logs[0], []byte("test")) {
779779
c.FailNowf("[ERR] first entry should be 'test'")
780780
}
781-
if bytes.Compare(fsm.logs[1], []byte("apply")) != 0 {
781+
if !bytes.Equal(fsm.logs[1], []byte("apply")) {
782782
c.FailNowf("[ERR] second entry should be 'apply'")
783783
}
784784
fsm.Unlock()

Diff for: internal/raft/transport_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func TestTransport_InstallSnapshot(t *testing.T) {
264264
rpc.Reader.Read(buf)
265265

266266
// Compare
267-
if bytes.Compare(buf, []byte("0123456789")) != 0 {
267+
if !bytes.Equal(buf, []byte("0123456789")) {
268268
t.Fatalf("bad buf %v", buf)
269269
}
270270

0 commit comments

Comments
 (0)