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

Function TestIJson

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

Source from the content-addressed store, hash-verified

698}
699
700func TestIJson(t *testing.T) {
701 initDb(t)
702 defer cleanupDb(t)
703 ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
704 defer cancelFn()
705 zoneId := uuid.NewString()
706 fileName := "ij1"
707 err := WFS.MakeFile(ctx, zoneId, fileName, nil, wshrpc.FileOpts{IJson: true})
708 if err != nil {
709 t.Fatalf("error creating file: %v", err)
710 }
711 rootSet := ijson.MakeSetCommand(nil, map[string]any{"tag": "div", "class": "root"})
712 err = WFS.AppendIJson(ctx, zoneId, fileName, rootSet)
713 if err != nil {
714 t.Fatalf("error appending ijson: %v", err)
715 }
716 _, fullData, err := WFS.ReadFile(ctx, zoneId, fileName)
717 if err != nil {
718 t.Fatalf("error reading file: %v", err)
719 }
720 cmds, err := ijson.ParseIJson(fullData)
721 if err != nil {
722 t.Fatalf("error parsing ijson: %v", err)
723 }
724 outData, err := ijson.ApplyCommands(nil, cmds, 0)
725 if err != nil {
726 t.Fatalf("error applying ijson: %v", err)
727 }
728 if !jsonDeepEqual(rootSet["data"], outData) {
729 t.Errorf("data mismatch: expected %v, got %v", rootSet["data"], outData)
730 }
731 childrenAppend := ijson.MakeAppendCommand(ijson.Path{"children"}, map[string]any{"tag": "div", "class": "child"})
732 err = WFS.AppendIJson(ctx, zoneId, fileName, childrenAppend)
733 if err != nil {
734 t.Fatalf("error appending ijson: %v", err)
735 }
736 _, fullData, err = WFS.ReadFile(ctx, zoneId, fileName)
737 if err != nil {
738 t.Fatalf("error reading file: %v", err)
739 }
740 cmds, err = ijson.ParseIJson(fullData)
741 if err != nil {
742 t.Fatalf("error parsing ijson: %v", err)
743 }
744 if len(cmds) != 2 {
745 t.Fatalf("command count mismatch: expected 2, got %d", len(cmds))
746 }
747 outData, err = ijson.ApplyCommands(nil, cmds, 0)
748 if err != nil {
749 t.Fatalf("error applying ijson: %v", err)
750 }
751 if !jsonDeepEqual(ijson.M{"tag": "div", "class": "root", "children": ijson.A{ijson.M{"tag": "div", "class": "child"}}}, outData) {
752 t.Errorf("data mismatch: expected %v, got %v", rootSet["data"], outData)
753 }
754 err = WFS.CompactIJson(ctx, zoneId, fileName)
755 if err != nil {
756 t.Fatalf("error compacting ijson: %v", err)
757 }

Callers

nothing calls this directly

Calls 11

MakeSetCommandFunction · 0.92
ParseIJsonFunction · 0.92
ApplyCommandsFunction · 0.92
MakeAppendCommandFunction · 0.92
initDbFunction · 0.85
cleanupDbFunction · 0.85
MakeFileMethod · 0.80
AppendIJsonMethod · 0.80
ReadFileMethod · 0.80
CompactIJsonMethod · 0.80
jsonDeepEqualFunction · 0.70

Tested by

no test coverage detected