(t *testing.T, coll *docstore.Collection, revField string)
| 1370 | } |
| 1371 | |
| 1372 | func testGetQueryKeyField(t *testing.T, coll *docstore.Collection, revField string) { |
| 1373 | t.Helper() |
| 1374 | |
| 1375 | // Query the key field of a collection that has one. |
| 1376 | // (The collection used for testGetQuery uses a key function rather than a key field.) |
| 1377 | ctx := context.Background() |
| 1378 | docs := []docmap{ |
| 1379 | {KeyField: "qkf1", "a": "one", revField: nil}, |
| 1380 | {KeyField: "qkf2", "a": "two", revField: nil}, |
| 1381 | {KeyField: "qkf3", "a": "three", revField: nil}, |
| 1382 | } |
| 1383 | al := coll.Actions() |
| 1384 | for _, d := range docs { |
| 1385 | al.Put(d) |
| 1386 | } |
| 1387 | if err := al.Do(ctx); err != nil { |
| 1388 | t.Fatal(err) |
| 1389 | } |
| 1390 | iter := coll.Query().Where(KeyField, "<", "qkf3").Get(ctx) |
| 1391 | defer iter.Stop() |
| 1392 | got := mustCollect(ctx, t, iter) |
| 1393 | want := docs[:2] |
| 1394 | diff := cmpDiff(got, want, cmpopts.SortSlices(sortByKeyField)) |
| 1395 | if diff != "" { |
| 1396 | t.Error(diff) |
| 1397 | } |
| 1398 | |
| 1399 | // Test that queries with selected fields always return the key. |
| 1400 | iter = coll.Query().Get(ctx, "a", docstore.FieldPath(revField)) |
| 1401 | defer iter.Stop() |
| 1402 | got = mustCollect(ctx, t, iter) |
| 1403 | for _, d := range docs { |
| 1404 | checkHasRevisionField(t, d, revField) |
| 1405 | } |
| 1406 | diff = cmpDiff(got, docs, cmpopts.SortSlices(sortByKeyField)) |
| 1407 | if diff != "" { |
| 1408 | t.Error(diff) |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | func sortByKeyField(d1, d2 docmap) bool { return d1[KeyField].(string) < d2[KeyField].(string) } |
| 1413 |
nothing calls this directly
no test coverage detected