diff --git a/internal/raft/file_snapshot.go b/internal/raft/file_snapshot.go index e0e49ae..b0a34e1 100644 --- a/internal/raft/file_snapshot.go +++ b/internal/raft/file_snapshot.go @@ -303,7 +303,7 @@ func (f *FileSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, error // Verify the hash computed := stateHash.Sum(nil) - if bytes.Compare(meta.CRC, computed) != 0 { + if !bytes.Equal(meta.CRC, computed) { f.logger.Printf("[ERR] snapshot: CRC checksum failed (stored: %v computed: %v)", meta.CRC, computed) fh.Close() diff --git a/internal/raft/file_snapshot_test.go b/internal/raft/file_snapshot_test.go index fcd2ef4..6c34744 100644 --- a/internal/raft/file_snapshot_test.go +++ b/internal/raft/file_snapshot_test.go @@ -133,7 +133,7 @@ func TestFileSS_CreateSnapshot(t *testing.T) { if latest.Term != 3 { t.Fatalf("bad snapshot: %v", *latest) } - if bytes.Compare(latest.Peers, peers) != 0 { + if !bytes.Equal(latest.Peers, peers) { t.Fatalf("bad snapshot: %v", *latest) } if latest.Size != 13 { @@ -156,7 +156,7 @@ func TestFileSS_CreateSnapshot(t *testing.T) { } // Ensure a match - if bytes.Compare(buf.Bytes(), []byte("first\nsecond\n")) != 0 { + if !bytes.Equal(buf.Bytes(), []byte("first\nsecond\n")) { t.Fatalf("content mismatch") } } diff --git a/internal/raft/integ_test.go b/internal/raft/integ_test.go index c4bf67a..2e2a949 100644 --- a/internal/raft/integ_test.go +++ b/internal/raft/integ_test.go @@ -146,7 +146,7 @@ CHECK: } for idx, log := range first.fsm.logs { other := env.fsm.logs[idx] - if bytes.Compare(log, other) != 0 { + if !bytes.Equal(log, other) { err = fmt.Errorf("log %d mismatch %v %v", idx, log, other) goto ERR } diff --git a/internal/raft/net_transport_test.go b/internal/raft/net_transport_test.go index ca92c89..6dc06fd 100644 --- a/internal/raft/net_transport_test.go +++ b/internal/raft/net_transport_test.go @@ -312,7 +312,7 @@ func TestNetworkTransport_InstallSnapshot(t *testing.T) { rpc.Reader.Read(buf) // Compare - if bytes.Compare(buf, []byte("0123456789")) != 0 { + if !bytes.Equal(buf, []byte("0123456789")) { t.Fatalf("bad buf %v", buf) } diff --git a/internal/raft/raft.go b/internal/raft/raft.go index 8c71835..2c9bca9 100644 --- a/internal/raft/raft.go +++ b/internal/raft/raft.go @@ -1485,7 +1485,7 @@ func (r *Raft) requestVote(rpc RPC, req *RequestVoteRequest) { // Check if we've voted in this election before if lastVoteTerm == req.Term && lastVoteCandBytes != nil { r.logger.Printf("[INFO] raft: Duplicate RequestVote for same term: %d", req.Term) - if bytes.Compare(lastVoteCandBytes, req.Candidate) == 0 { + if bytes.Equal(lastVoteCandBytes, req.Candidate) { r.logger.Printf("[WARN] raft: Duplicate RequestVote from candidate: %s", req.Candidate) resp.Granted = true } diff --git a/internal/raft/raft_test.go b/internal/raft/raft_test.go index 5eb660a..0f59e4d 100644 --- a/internal/raft/raft_test.go +++ b/internal/raft/raft_test.go @@ -464,7 +464,7 @@ CHECK: } for idx := 0; idx < len(first.logs); idx++ { - if bytes.Compare(first.logs[idx], fsm.logs[idx]) != 0 { + if !bytes.Equal(first.logs[idx], fsm.logs[idx]) { fsm.Unlock() if time.Now().After(limit) { c.FailNowf("[ERR] FSM log mismatch at index %d", idx) @@ -775,10 +775,10 @@ func TestRaft_LeaderFail(t *testing.T) { if len(fsm.logs) != 2 { c.FailNowf("[ERR] did not apply both to FSM! %v", fsm.logs) } - if bytes.Compare(fsm.logs[0], []byte("test")) != 0 { + if !bytes.Equal(fsm.logs[0], []byte("test")) { c.FailNowf("[ERR] first entry should be 'test'") } - if bytes.Compare(fsm.logs[1], []byte("apply")) != 0 { + if !bytes.Equal(fsm.logs[1], []byte("apply")) { c.FailNowf("[ERR] second entry should be 'apply'") } fsm.Unlock() diff --git a/internal/raft/transport_test.go b/internal/raft/transport_test.go index e3cbd52..2fb1949 100644 --- a/internal/raft/transport_test.go +++ b/internal/raft/transport_test.go @@ -264,7 +264,7 @@ func TestTransport_InstallSnapshot(t *testing.T) { rpc.Reader.Read(buf) // Compare - if bytes.Compare(buf, []byte("0123456789")) != 0 { + if !bytes.Equal(buf, []byte("0123456789")) { t.Fatalf("bad buf %v", buf) }