MCPcopy Create free account
hub / github.com/google/go-cloud / TestSet

Function TestSet

docstore/driver/document_test.go:103–141  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

101}
102
103func TestSet(t *testing.T) {
104 in := map[string]any{
105 "S": &S{
106 I: 2,
107 M: map[string]any{
108 "J": 3,
109 "T": &S{I: 4},
110 },
111 },
112 }
113 doc, err := NewDocument(in)
114 if err != nil {
115 t.Fatal(err)
116 }
117 for _, test := range []struct {
118 fp string
119 val any
120 }{
121 {"S.I", -1},
122 {"S.i", -2},
123 {"S.M.J", -3},
124 {"S.m.J", -4},
125 {"S.M.T.I", -5},
126 {"S.m.T.i", -6},
127 {"new.field", -7},
128 } {
129 fp := strings.Split(test.fp, ".")
130 if err := doc.Set(fp, test.val); err != nil {
131 t.Fatalf("%q: %v", test.fp, err)
132 }
133 got, err := doc.Get(fp)
134 if err != nil {
135 t.Fatalf("%s: %v", test.fp, err)
136 }
137 if !cmp.Equal(got, test.val) {
138 t.Errorf("got %v, want %v", got, test.val)
139 }
140 }
141}
142
143func TestGetField(t *testing.T) {
144 type S struct {

Callers

nothing calls this directly

Calls 3

SetMethod · 0.95
GetMethod · 0.95
NewDocumentFunction · 0.85

Tested by

no test coverage detected