2026-04-29 22:08:08 +08:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"reflect"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
sharedcache "github.com/geo-platform/tenant-api/internal/shared/cache"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type recordingCache struct {
|
|
|
|
|
deletedKeys []string
|
|
|
|
|
deletedPrefixes []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *recordingCache) Get(context.Context, string) ([]byte, error) {
|
|
|
|
|
return nil, sharedcache.ErrNotFound
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-03 02:02:39 +08:00
|
|
|
func (c *recordingCache) GetMulti(context.Context, []string) (map[string][]byte, error) {
|
|
|
|
|
return map[string][]byte{}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-29 22:08:08 +08:00
|
|
|
func (c *recordingCache) Set(context.Context, string, []byte, time.Duration) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-03 02:02:39 +08:00
|
|
|
func (c *recordingCache) SetMulti(context.Context, []sharedcache.Item) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-29 22:08:08 +08:00
|
|
|
func (c *recordingCache) Delete(_ context.Context, key string) error {
|
|
|
|
|
c.deletedKeys = append(c.deletedKeys, key)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-03 02:02:39 +08:00
|
|
|
func (c *recordingCache) DeleteMany(_ context.Context, keys []string) error {
|
|
|
|
|
c.deletedKeys = append(c.deletedKeys, keys...)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-29 22:08:08 +08:00
|
|
|
func (c *recordingCache) DeletePrefix(_ context.Context, prefix string) error {
|
|
|
|
|
c.deletedPrefixes = append(c.deletedPrefixes, prefix)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestKolSubscriptionInvalidateAccessCaches(t *testing.T) {
|
|
|
|
|
cache := &recordingCache{}
|
|
|
|
|
svc := NewKolSubscriptionService(nil, nil).WithCache(cache)
|
|
|
|
|
|
|
|
|
|
svc.invalidateAccessCaches(context.Background(), 42)
|
|
|
|
|
|
|
|
|
|
if want := []string{"workspace:kol_cards:42"}; !reflect.DeepEqual(cache.deletedKeys, want) {
|
|
|
|
|
t.Fatalf("deleted keys = %v, want %v", cache.deletedKeys, want)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wantPrefixes := []string{
|
|
|
|
|
"kol:subscription_prompt:list:42:",
|
|
|
|
|
"kol:subscription_prompt:schema:42:",
|
2026-05-24 11:33:17 +08:00
|
|
|
"kol:marketplace:",
|
2026-04-29 22:08:08 +08:00
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(cache.deletedPrefixes, wantPrefixes) {
|
|
|
|
|
t.Fatalf("deleted prefixes = %v, want %v", cache.deletedPrefixes, wantPrefixes)
|
|
|
|
|
}
|
|
|
|
|
}
|