certichain

Blockchain built from scratch for verifying document's legitimacy.
Log | Files | Refs | README | LICENSE

commit fae92e66e93ffd78a86ff7644bff032c75e68bab
parent aad5a55b64ed2d44da2e3022914af16f18706b22
Author: Shivakumar <[email protected]>
Date:   Sat, 30 May 2026 16:12:10 +0530

test(storage): add missing test cases
- add empty value test case
- add clone mutate test case

Signed-off-by: Shivakumar <[email protected]>

Diffstat:
Minternal/storage/storage_test.go | 19++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/internal/storage/storage_test.go b/internal/storage/storage_test.go @@ -87,18 +87,35 @@ func runStoreSuite(t *testing.T, s Store) { } }) - t.Run("Empty key guards", func(t *testing.T) { + t.Run("Empty guards", func(t *testing.T) { if err := s.Set(nil, []byte("VAL")); !errors.Is(err, ErrEmptyKey) { t.Errorf("Set nil key: expected ErrEmptyKey, got %v", err) } if err := s.Set([]byte{}, []byte("VAL")); !errors.Is(err, ErrEmptyKey) { t.Errorf("Set empty key: expected ErrEmptyKey, got %v", err) } + if err := s.Set([]byte("KEY"), nil); !errors.Is(err, ErrEmptyValue) { + t.Errorf("Set nil value: expected ErrEmptyValue, got %v", err) + } + if err := s.Set([]byte("KEY"), []byte{}); !errors.Is(err, ErrEmptyValue) { + t.Errorf("Set empty value: expected ErrEmptyValue, got %v", err) + } if _, err := s.Get(nil); !errors.Is(err, ErrEmptyKey) { t.Errorf("Get nil key: expected ErrEmptyKey, got %v", err) } }) + t.Run("Set clones input value", func(t *testing.T) { + key := []byte("CLONE_SET_KEY") + val := []byte("ORIGINAL") + s.Set(key, val) + val[0] = 'X' // mutate after set + got, _ := s.Get(key) + if !bytes.Equal([]byte("ORIGINAL"), got) { + t.Error("Set did not clone input — stored value was mutated by caller") + } + }) + t.Run("Iterate respects prefix", func(t *testing.T) { // Setup mixed keys keys := [][]byte{