MCPcopy Create free account
hub / github.com/devld/go-drive / TestSharedStateIsCopiedBetweenVMs

Function TestSharedStateIsCopiedBetweenVMs

drive/script/shared_state_test.go:28–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26}
27
28func TestSharedStateIsCopiedBetweenVMs(t *testing.T) {
29 d := &ScriptDrive{data: make(map[string]json.RawMessage)}
30 first := newSharedStateTestVM(t, d)
31 second := first.Fork()
32 t.Cleanup(func() { _ = second.Dispose() })
33
34 if _, e := first.Run(context.Background(), `setData({state: {count: 1, values: ["a"]}})`); e != nil {
35 t.Fatal(e)
36 }
37 if _, e := second.Run(context.Background(), `var local = getData("state"); local.count = 2; local.values.push("b")`); e != nil {
38 t.Fatal(e)
39 }
40 value, e := first.Run(context.Background(), `JSON.stringify(getData("state"))`)
41 if e != nil {
42 t.Fatal(e)
43 }
44 if got := value.String(); got != `{"count":1,"values":["a"]}` {
45 t.Fatalf("nested mutation changed shared state: %s", got)
46 }
47
48 if _, e := second.Run(context.Background(), `setData({state: local})`); e != nil {
49 t.Fatal(e)
50 }
51 value, e = first.Run(context.Background(), `JSON.stringify(getData("state"))`)
52 if e != nil {
53 t.Fatal(e)
54 }
55 if got := value.String(); got != `{"count":2,"values":["a","b"]}` {
56 t.Fatalf("reassigned shared state was not persisted: %s", got)
57 }
58}
59
60func TestSharedStateRejectsNonJSONValues(t *testing.T) {
61 for name, code := range map[string]string{

Callers

nothing calls this directly

Calls 5

newSharedStateTestVMFunction · 0.85
ForkMethod · 0.80
RunMethod · 0.80
DisposeMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected