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

Function TestWriteFile

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

Source from the content-addressed store, hash-verified

370}
371
372func TestWriteFile(t *testing.T) {
373 initDb(t)
374 defer cleanupDb(t)
375
376 ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
377 defer cancelFn()
378 zoneId := uuid.NewString()
379 fileName := "t3"
380 err := WFS.MakeFile(ctx, zoneId, fileName, nil, wshrpc.FileOpts{})
381 if err != nil {
382 t.Fatalf("error creating file: %v", err)
383 }
384 err = WFS.WriteFile(ctx, zoneId, fileName, []byte("hello world!"))
385 if err != nil {
386 t.Fatalf("error writing data: %v", err)
387 }
388 checkFileData(t, ctx, zoneId, fileName, "hello world!")
389 err = WFS.WriteFile(ctx, zoneId, fileName, []byte("goodbye world!"))
390 if err != nil {
391 t.Fatalf("error writing data: %v", err)
392 }
393 checkFileData(t, ctx, zoneId, fileName, "goodbye world!")
394 err = WFS.WriteFile(ctx, zoneId, fileName, []byte("hello"))
395 if err != nil {
396 t.Fatalf("error writing data: %v", err)
397 }
398 checkFileData(t, ctx, zoneId, fileName, "hello")
399
400 // circular file
401 err = WFS.MakeFile(ctx, zoneId, "c1", nil, wshrpc.FileOpts{Circular: true, MaxSize: 50})
402 if err != nil {
403 t.Fatalf("error creating file: %v", err)
404 }
405 err = WFS.WriteFile(ctx, zoneId, "c1", []byte("123456789 123456789 123456789 123456789 123456789 apple"))
406 if err != nil {
407 t.Fatalf("error writing data: %v", err)
408 }
409 checkFileData(t, ctx, zoneId, "c1", "6789 123456789 123456789 123456789 123456789 apple")
410 err = WFS.AppendData(ctx, zoneId, "c1", []byte(" banana"))
411 if err != nil {
412 t.Fatalf("error appending data: %v", err)
413 }
414 checkFileData(t, ctx, zoneId, "c1", "3456789 123456789 123456789 123456789 apple banana")
415}
416
417func TestCircularWrites(t *testing.T) {
418 initDb(t)

Callers

nothing calls this directly

Calls 6

initDbFunction · 0.85
cleanupDbFunction · 0.85
checkFileDataFunction · 0.85
MakeFileMethod · 0.80
WriteFileMethod · 0.80
AppendDataMethod · 0.80

Tested by

no test coverage detected