MCPcopy
hub / github.com/wavetermdev/waveterm / TestSetMeta

Function TestSetMeta

pkg/filestore/blockstore_test.go:216–263  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

214}
215
216func TestSetMeta(t *testing.T) {
217 initDb(t)
218 defer cleanupDb(t)
219
220 ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
221 defer cancelFn()
222 zoneId := uuid.NewString()
223 err := WFS.MakeFile(ctx, zoneId, "testfile", nil, wshrpc.FileOpts{})
224 if err != nil {
225 t.Fatalf("error creating file: %v", err)
226 }
227 if WFS.getCacheSize() != 0 {
228 t.Errorf("cache size mismatch -- should have 0 entries after create")
229 }
230 err = WFS.WriteMeta(ctx, zoneId, "testfile", map[string]any{"a": 5, "b": "hello", "q": 8}, false)
231 if err != nil {
232 t.Fatalf("error setting meta: %v", err)
233 }
234 file, err := WFS.Stat(ctx, zoneId, "testfile")
235 if err != nil {
236 t.Fatalf("error stating file: %v", err)
237 }
238 if file == nil {
239 t.Fatalf("file not found")
240 }
241 checkMapsEqual(t, map[string]any{"a": 5, "b": "hello", "q": 8}, file.Meta, "meta")
242 if WFS.getCacheSize() != 1 {
243 t.Errorf("cache size mismatch")
244 }
245 err = WFS.WriteMeta(ctx, zoneId, "testfile", map[string]any{"a": 6, "c": "world", "d": 7, "q": nil}, true)
246 if err != nil {
247 t.Fatalf("error setting meta: %v", err)
248 }
249 file, err = WFS.Stat(ctx, zoneId, "testfile")
250 if err != nil {
251 t.Fatalf("error stating file: %v", err)
252 }
253 if file == nil {
254 t.Fatalf("file not found")
255 }
256 checkMapsEqual(t, map[string]any{"a": 6, "b": "hello", "c": "world", "d": 7}, file.Meta, "meta")
257
258 err = WFS.WriteMeta(ctx, zoneId, "testfile-notexist", map[string]any{"a": 6}, true)
259 if err == nil {
260 t.Fatalf("expected error setting meta")
261 }
262 err = nil
263}
264
265func checkFileSize(t *testing.T, ctx context.Context, zoneId string, name string, size int64) {
266 file, err := WFS.Stat(ctx, zoneId, name)

Callers

nothing calls this directly

Calls 7

initDbFunction · 0.85
cleanupDbFunction · 0.85
checkMapsEqualFunction · 0.85
MakeFileMethod · 0.80
getCacheSizeMethod · 0.80
WriteMetaMethod · 0.80
StatMethod · 0.80

Tested by

no test coverage detected