tests(scopestore): add tests

This commit is contained in:
Enot (ded) Skelly
2026-06-15 14:13:49 -07:00
parent 16b4394b30
commit b8472a5504
+54
View File
@@ -0,0 +1,54 @@
// Copyright 2026 Beacon Contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
package scopestore
import (
"testing"
)
func TestNew_Empty(t *testing.T) {
s := New()
if len(s.Entries()) != 0 {
t.Errorf("expected empty store, got %d entries", len(s.Entries()))
}
}
func TestLoad_ReplacesEntries(t *testing.T) {
s := New()
s.Load([]Entry{
{Name: "#bc", TransportKey: []byte{0x01}, KeyFingerprint: []byte{0x02}},
})
entries := s.Entries()
if len(entries) != 1 {
t.Fatalf("expected 1 entry, got %d", len(entries))
}
if entries[0].Name != "#bc" {
t.Errorf("expected #bc, got %s", entries[0].Name)
}
// replace with new entries
s.Load([]Entry{
{Name: "#west", TransportKey: []byte{0x03}, KeyFingerprint: []byte{0x04}},
{Name: "#east", TransportKey: []byte{0x05}, KeyFingerprint: []byte{0x06}},
})
entries = s.Entries()
if len(entries) != 2 {
t.Fatalf("expected 2 entries after reload, got %d", len(entries))
}
}
func TestEntries_ReturnsCopy(t *testing.T) {
s := New()
s.Load([]Entry{
{Name: "#bc", TransportKey: []byte{0x01}, KeyFingerprint: []byte{0x02}},
})
entries := s.Entries()
entries[0].Name = "mutated"
// original should be unchanged
original := s.Entries()
if original[0].Name != "#bc" {
t.Errorf("expected #bc, got %s after mutation of copy", original[0].Name)
}
}