From 04ed63736648ed5683db40f85098c71ab41410d2 Mon Sep 17 00:00:00 2001 From: Amshith Nair Date: Sun, 15 Mar 2026 20:32:57 +0530 Subject: [PATCH] =?UTF-8?q?test(hash):=20add=20unit=20tests=20for=20Hash,?= =?UTF-8?q?=20Hash=20determinism,=20and=20Md5Hex=20edg=E2=80=A6=20(#5469)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/hash/hash_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/hash/hash_test.go b/core/hash/hash_test.go index 5e0962a78..e2f043187 100644 --- a/core/hash/hash_test.go +++ b/core/hash/hash_test.go @@ -25,6 +25,29 @@ func TestMd5Hex(t *testing.T) { assert.Equal(t, md5Digest, actual) } +func TestHash(t *testing.T) { + result := Hash([]byte(text)) + assert.NotEqual(t, uint64(0), result) +} + +func TestHash_Deterministic(t *testing.T) { + data := []byte("consistent-hash-test") + first := Hash(data) + second := Hash(data) + assert.Equal(t, first, second) +} + +func TestHash_Empty(t *testing.T) { + // Hash should not panic on empty input. + result := Hash([]byte{}) + _ = result +} + +func TestMd5Hex_Empty(t *testing.T) { + result := Md5Hex([]byte{}) + assert.Equal(t, 32, len(result)) +} + func BenchmarkHashFnv(b *testing.B) { for i := 0; i < b.N; i++ { h := fnv.New32()