MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / TestNamespacedCacheIsolation

Function TestNamespacedCacheIsolation

internal/cache/cache_test.go:116–163  ·  view source on GitHub ↗

TestNamespacedCacheIsolation verifies that namespaced caches are not affected by clearing the global cache.

(t *testing.T)

Source from the content-addressed store, hash-verified

114
115// TestNamespacedCacheIsolation verifies that namespaced caches are not affected by clearing the global cache.
116func TestNamespacedCacheIsolation(t *testing.T) {
117 resetCacheState()
118 defer resetCacheState()
119
120 cacheDir := t.TempDir()
121
122 if err := InitGlobalCache(cacheDir); err != nil {
123 t.Fatalf("InitGlobalCache: %v", err)
124 }
125
126 global := GetGlobalCache()
127 defer func() {
128 _ = global.Close()
129 }()
130
131 nsCache := GetNamespacedCache("test-plugin")
132 defer func() {
133 _ = nsCache.Close()
134 }()
135
136 type payload struct {
137 Value string
138 }
139
140 item := payload{Value: "persist"}
141
142 if err := nsCache.Set("ns-key", item, time.Hour); err != nil {
143 t.Fatalf("namespaced set: %v", err)
144 }
145
146 if err := global.Clear(); err != nil {
147 t.Fatalf("global clear: %v", err)
148 }
149
150 var got payload
151 found, err := nsCache.Get("ns-key", &got)
152 if err != nil {
153 t.Fatalf("namespaced get: %v", err)
154 }
155
156 if !found {
157 t.Fatal("expected namespaced cache item to persist after global clear")
158 }
159
160 if got != item {
161 t.Fatalf("expected %v, got %v", item, got)
162 }
163}

Callers

nothing calls this directly

Calls 8

resetCacheStateFunction · 0.85
InitGlobalCacheFunction · 0.85
GetGlobalCacheFunction · 0.85
GetNamespacedCacheFunction · 0.85
CloseMethod · 0.65
SetMethod · 0.65
ClearMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected