diff --git a/bench_test.go b/bench_test.go index 47404114e..354fc3956 100644 --- a/bench_test.go +++ b/bench_test.go @@ -151,7 +151,7 @@ func BenchmarkMinimalPgConnPreparedSelect(b *testing.B) { for rr.NextRow() { for i := range rr.Values() { - if bytes.Compare(rr.Values()[0], encodedBytes) != 0 { + if !bytes.Equal(rr.Values()[0], encodedBytes) { b.Fatalf("unexpected values: %s %s", rr.Values()[i], encodedBytes) } } diff --git a/conn_test.go b/conn_test.go index 14bfd7e81..25cab7a1d 100644 --- a/conn_test.go +++ b/conn_test.go @@ -1242,7 +1242,7 @@ func TestRawValuesUnderlyingMemoryReused(t *testing.T) { rows.Close() require.NoError(t, rows.Err()) - if bytes.Compare(original, buf) != 0 { + if !bytes.Equal(original, buf) { return } } diff --git a/pgproto3/chunkreader_test.go b/pgproto3/chunkreader_test.go index e1c2b0da7..f509fb6eb 100644 --- a/pgproto3/chunkreader_test.go +++ b/pgproto3/chunkreader_test.go @@ -17,7 +17,7 @@ func TestChunkReaderNextDoesNotReadIfAlreadyBuffered(t *testing.T) { if err != nil { t.Fatal(err) } - if bytes.Compare(n1, src[0:2]) != 0 { + if !bytes.Equal(n1, src[0:2]) { t.Fatalf("Expected read bytes to be %v, but they were %v", src[0:2], n1) } @@ -25,11 +25,11 @@ func TestChunkReaderNextDoesNotReadIfAlreadyBuffered(t *testing.T) { if err != nil { t.Fatal(err) } - if bytes.Compare(n2, src[2:4]) != 0 { + if !bytes.Equal(n2, src[2:4]) { t.Fatalf("Expected read bytes to be %v, but they were %v", src[2:4], n2) } - if bytes.Compare((*r.buf)[:len(src)], src) != 0 { + if !bytes.Equal((*r.buf)[:len(src)], src) { t.Fatalf("Expected r.buf to be %v, but it was %v", src, r.buf) } diff --git a/pgtype/bits_test.go b/pgtype/bits_test.go index 767f0d2b1..d517df2b8 100644 --- a/pgtype/bits_test.go +++ b/pgtype/bits_test.go @@ -13,7 +13,7 @@ func isExpectedEqBits(a any) func(any) bool { return func(v any) bool { ab := a.(pgtype.Bits) vb := v.(pgtype.Bits) - return bytes.Compare(ab.Bytes, vb.Bytes) == 0 && ab.Len == vb.Len && ab.Valid == vb.Valid + return bytes.Equal(ab.Bytes, vb.Bytes) && ab.Len == vb.Len && ab.Valid == vb.Valid } } diff --git a/pgtype/bytea_test.go b/pgtype/bytea_test.go index 336ad2530..4985e7a97 100644 --- a/pgtype/bytea_test.go +++ b/pgtype/bytea_test.go @@ -25,7 +25,7 @@ func isExpectedEqBytes(a any) func(any) bool { return true } - return bytes.Compare(ab, vb) == 0 + return bytes.Equal(ab, vb) } } @@ -64,7 +64,7 @@ func TestDriverBytes(t *testing.T) { rowCount++ // At some point the buffer should be reused and change. - if bytes.Compare(argBuf, resultBuf) != 0 { + if !bytes.Equal(argBuf, resultBuf) { detectedResultMutation = true } diff --git a/pgtype/macaddr_test.go b/pgtype/macaddr_test.go index ef6dae003..84cf970f3 100644 --- a/pgtype/macaddr_test.go +++ b/pgtype/macaddr_test.go @@ -22,7 +22,7 @@ func isExpectedEqHardwareAddr(a any) func(any) bool { return true } - return bytes.Compare(aa, vv) == 0 + return bytes.Equal(aa, vv) } } diff --git a/pgtype/numeric.go b/pgtype/numeric.go index 376c03fe8..4e0ccc9a1 100644 --- a/pgtype/numeric.go +++ b/pgtype/numeric.go @@ -241,11 +241,11 @@ func (n Numeric) MarshalJSON() ([]byte, error) { } func (n *Numeric) UnmarshalJSON(src []byte) error { - if bytes.Compare(src, []byte(`null`)) == 0 { + if bytes.Equal(src, []byte(`null`)) { *n = Numeric{} return nil } - if bytes.Compare(src, []byte(`"NaN"`)) == 0 { + if bytes.Equal(src, []byte(`"NaN"`)) { *n = Numeric{NaN: true, Valid: true} return nil } diff --git a/pgtype/point.go b/pgtype/point.go index cfa5a9f1a..b5a4320b6 100644 --- a/pgtype/point.go +++ b/pgtype/point.go @@ -40,7 +40,7 @@ func (p Point) PointValue() (Point, error) { } func parsePoint(src []byte) (*Point, error) { - if src == nil || bytes.Compare(src, []byte("null")) == 0 { + if src == nil || bytes.Equal(src, []byte("null")) { return &Point{}, nil } diff --git a/pgtype/range_test.go b/pgtype/range_test.go index 1ee8d5533..eb9486b08 100644 --- a/pgtype/range_test.go +++ b/pgtype/range_test.go @@ -166,11 +166,11 @@ func TestParseUntypedBinaryRange(t *testing.T) { t.Errorf("%d. `%v`: expected result upper type %v, got %v", i, tt.src, string(tt.result.UpperType), string(r.UpperType)) } - if bytes.Compare(r.Lower, tt.result.Lower) != 0 { + if !bytes.Equal(r.Lower, tt.result.Lower) { t.Errorf("%d. `%v`: expected result lower %v, got %v", i, tt.src, tt.result.Lower, r.Lower) } - if bytes.Compare(r.Upper, tt.result.Upper) != 0 { + if !bytes.Equal(r.Upper, tt.result.Upper) { t.Errorf("%d. `%v`: expected result upper %v, got %v", i, tt.src, tt.result.Upper, r.Upper) } } diff --git a/pgtype/uuid.go b/pgtype/uuid.go index 96a4c32fd..b59d6e766 100644 --- a/pgtype/uuid.go +++ b/pgtype/uuid.go @@ -97,7 +97,7 @@ func (src UUID) MarshalJSON() ([]byte, error) { } func (dst *UUID) UnmarshalJSON(src []byte) error { - if bytes.Compare(src, []byte("null")) == 0 { + if bytes.Equal(src, []byte("null")) { *dst = UUID{} return nil } diff --git a/query_test.go b/query_test.go index 9896df0dc..39585a600 100644 --- a/query_test.go +++ b/query_test.go @@ -1518,7 +1518,7 @@ func TestConnSimpleProtocol(t *testing.T) { if err != nil { t.Error(err) } - if bytes.Compare(actual, expected) != 0 { + if !bytes.Equal(actual, expected) { t.Errorf("expected %v got %v", expected, actual) } } @@ -1825,7 +1825,7 @@ func TestConnSimpleProtocol(t *testing.T) { if expectedBool != actualBool { t.Errorf("expected %v got %v", expectedBool, actualBool) } - if bytes.Compare(expectedBytes, actualBytes) != 0 { + if !bytes.Equal(expectedBytes, actualBytes) { t.Errorf("expected %v got %v", expectedBytes, actualBytes) } if expectedString != actualString { diff --git a/stdlib/sql_test.go b/stdlib/sql_test.go index e7d77417a..9868cf318 100644 --- a/stdlib/sql_test.go +++ b/stdlib/sql_test.go @@ -547,7 +547,7 @@ func TestConnQueryJSONIntoByteSlice(t *testing.T) { t.Errorf("Unexpected failure: %v (sql -> %v)", err, sql) } - if bytes.Compare(actual, expected) != 0 { + if !bytes.Equal(actual, expected) { t.Errorf(`Expected "%v", got "%v" (sql -> %v)`, string(expected), string(actual), sql) } @@ -579,7 +579,7 @@ func TestConnExecInsertByteSliceIntoJSON(t *testing.T) { err = db.QueryRow(`select body from docs`).Scan(&actual) require.NoError(t, err) - if bytes.Compare(actual, expected) != 0 { + if !bytes.Equal(actual, expected) { t.Errorf(`Expected "%v", got "%v"`, string(expected), string(actual)) }