(t *testing.T)
| 136 | } |
| 137 | |
| 138 | func 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 | }, { |
nothing calls this directly
no test coverage detected