(t *testing.T)
| 26 | } |
| 27 | |
| 28 | func 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 | |
| 60 | func TestSharedStateRejectsNonJSONValues(t *testing.T) { |
| 61 | for name, code := range map[string]string{ |
nothing calls this directly
no test coverage detected