aboutsummaryrefslogtreecommitdiff
path: root/objectid/objectid_test.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-02-21 10:05:19 +0800
committerGravatar Runxi Yu2026-02-21 11:00:52 +0800
commit1334ea3e45aaf9d2620223215763443647aae5a7 (patch)
treeefe900b59f7f70ddc13d830ea027db7e7bd44ad6 /objectid/objectid_test.go
parenttestgit: Add git repack (diff)
signatureNo signature
objectid: Add RawBytes
Diffstat (limited to 'objectid/objectid_test.go')
-rw-r--r--objectid/objectid_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/objectid/objectid_test.go b/objectid/objectid_test.go
index ea4e9f44..7abeb963 100644
--- a/objectid/objectid_test.go
+++ b/objectid/objectid_test.go
@@ -127,6 +127,29 @@ func TestBytesReturnsCopy(t *testing.T) {
}
}
+func TestRawBytesAliasesStorage(t *testing.T) {
+ t.Parallel()
+
+ id, err := objectid.ParseHex(objectid.AlgorithmSHA1, "0123456789abcdef0123456789abcdef01234567")
+ if err != nil {
+ t.Fatalf("ParseHex failed: %v", err)
+ }
+
+ b := id.RawBytes()
+ if len(b) != id.Size() {
+ t.Fatalf("RawBytes len = %d, want %d", len(b), id.Size())
+ }
+ if cap(b) != len(b) {
+ t.Fatalf("RawBytes cap = %d, want %d", cap(b), len(b))
+ }
+
+ orig := id.String()
+ b[0] ^= 0xff
+ if id.String() == orig {
+ t.Fatalf("RawBytes should alias object ID storage")
+ }
+}
+
func TestAlgorithmSum(t *testing.T) {
t.Parallel()