Files
memby/server/internal/cache/cache_test.go
2026-08-19 18:08:00 +12:00

30 lines
1.1 KiB
Go

package cache
import "testing"
// The index name is derived from the key rather than passed in, so this is the whole of
// what stands between a user-scoped write and an invalidation that misses it.
func TestUserIndexFor(t *testing.T) {
cases := []struct {
name string
key string
want string
}{
{"user view", UserKey("abc123", "home:v4:24"), "idx:u:abc123"},
{"view containing colons", UserKey("abc123", "item:v6:9f:2"), "idx:u:abc123"},
{"recommendations are deliberately outside the namespace", RecommendationsKey("abc"), ""},
{"magic pool likewise", MagicPoolKey("abc"), ""},
{"household metadata belongs to nobody", MetadataKey("person:v2:44"), ""},
{"a session is not a view", SessionKey("deadbeef"), ""},
{"a malformed user key indexes nothing rather than guessing", "u:", ""},
{"a user key with no view is not a view either", "u:abc", ""},
}
for _, test := range cases {
t.Run(test.name, func(t *testing.T) {
if got := userIndexFor(test.key); got != test.want {
t.Fatalf("userIndexFor(%q) = %q, want %q", test.key, got, test.want)
}
})
}
}