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

Function testGetQueryKeyField

docstore/drivertest/drivertest.go:1372–1410  ·  view source on GitHub ↗
(t *testing.T, coll *docstore.Collection, revField string)

Source from the content-addressed store, hash-verified

1370}
1371
1372func 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
1412func sortByKeyField(d1, d2 docmap) bool { return d1[KeyField].(string) < d2[KeyField].(string) }
1413

Callers

nothing calls this directly

Calls 12

FieldPathTypeAlias · 0.92
mustCollectFunction · 0.85
cmpDiffFunction · 0.85
checkHasRevisionFieldFunction · 0.85
ActionsMethod · 0.80
DoMethod · 0.80
WhereMethod · 0.80
QueryMethod · 0.80
StopMethod · 0.65
PutMethod · 0.45
GetMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected