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

Function TestQueryNested

docstore/memdocstore/mem_test.go:138–272  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

136}
137
138func TestQueryNested(t *testing.T) {
139 ctx := context.Background()
140
141 dc, err := newCollection(drivertest.KeyField, nil, &Options{AllowNestedSliceQueries: true})
142 if err != nil {
143 t.Fatal(err)
144 }
145 coll := docstore.NewCollection(dc)
146 defer coll.Close()
147
148 // Set up test documents
149 testDocs := []docmap{{
150 drivertest.KeyField: "TestQueryNested",
151 "list": []any{docmap{"a": "A"}},
152 "map": docmap{"b": "B"},
153 "listOfMaps": []any{docmap{"id": "1"}, docmap{"id": "2"}, docmap{"id": "3"}},
154 "mapOfLists": docmap{"ids": []any{"1", "2", "3"}},
155 "deep": []any{docmap{"nesting": []any{docmap{"of": docmap{"elements": "yes"}}}}},
156 "listOfLists": []any{docmap{"items": []any{docmap{"price": 10}, docmap{"price": 20}}}},
157 dc.RevisionField(): nil,
158 }, {
159 drivertest.KeyField: "CheapItems",
160 "items": []any{docmap{"price": 10}, docmap{"price": 1}},
161 dc.RevisionField(): nil,
162 }, {
163 drivertest.KeyField: "ExpensiveItems",
164 "items": []any{docmap{"price": 50}, docmap{"price": 100}},
165 dc.RevisionField(): nil,
166 }}
167
168 for _, testDoc := range testDocs {
169 err = coll.Put(ctx, testDoc)
170 if err != nil {
171 t.Fatal(err)
172 }
173 }
174
175 tests := []struct {
176 name string
177 where []any
178 wantKeys []string
179 }{
180 {
181 name: "list field match",
182 where: []any{"list.a", "=", "A"},
183 wantKeys: []string{"TestQueryNested"},
184 }, {
185 name: "list field no match",
186 where: []any{"list.a", "=", "missing"},
187 }, {
188 name: "map field match",
189 where: []any{"map.b", "=", "B"},
190 wantKeys: []string{"TestQueryNested"},
191 }, {
192 name: "list of maps field match",
193 where: []any{"listOfMaps.id", "=", "2"},
194 wantKeys: []string{"TestQueryNested"},
195 }, {

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
PutMethod · 0.95
QueryMethod · 0.95
FieldPathTypeAlias · 0.92
WhereMethod · 0.80
newCollectionFunction · 0.70
RevisionFieldMethod · 0.65
NextMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected