MCPcopy Index your code
hub / github.com/perkeep/perkeep / testQueryRecentPermanodes_ContinueEndMidPage

Function testQueryRecentPermanodes_ContinueEndMidPage

pkg/search/query_test.go:1307–1364  ·  view source on GitHub ↗

Tests continue token hitting the end mid-page.

(t *testing.T, sortType SortType)

Source from the content-addressed store, hash-verified

1305
1306// Tests continue token hitting the end mid-page.
1307func testQueryRecentPermanodes_ContinueEndMidPage(t *testing.T, sortType SortType) {
1308 testQueryTypes(t, memIndexTypes, func(qt *queryTest) {
1309 id := qt.id
1310
1311 var blobs []blob.Ref
1312 for i := 1; i <= 3; i++ {
1313 pn := id.NewPlannedPermanode(fmt.Sprint(i))
1314 blobs = append(blobs, pn)
1315 t.Logf("permanode %d is %v", i, pn)
1316 id.SetAttribute_NoTimeMove(pn, "foo", "bar")
1317 }
1318 sort.Sort(blob.ByRef(blobs))
1319 for i, br := range blobs {
1320 t.Logf("Sorted %d = %v", i, br)
1321 }
1322 handler := qt.Handler()
1323
1324 contToken := ""
1325 tests := [][]blob.Ref{
1326 {blobs[2], blobs[1]},
1327 {blobs[0]},
1328 }
1329
1330 for i, wantBlobs := range tests {
1331 req := &SearchQuery{
1332 Constraint: &Constraint{
1333 Permanode: &PermanodeConstraint{},
1334 },
1335 Limit: 2,
1336 Sort: sortType,
1337 Continue: contToken,
1338 }
1339 res, err := handler.Query(ctxbg, req)
1340 if err != nil {
1341 qt.t.Fatalf("Error on query %d: %v", i+1, err)
1342 }
1343 t.Logf("Query %d/%d: continue = %q", i+1, len(tests), res.Continue)
1344 for i, sb := range res.Blobs {
1345 t.Logf(" res[%d]: %v", i, sb.Blob)
1346 }
1347
1348 var want []*SearchResultBlob
1349 for _, br := range wantBlobs {
1350 want = append(want, &SearchResultBlob{Blob: br})
1351 }
1352 if !reflect.DeepEqual(res.Blobs, want) {
1353 gotj, wantj := prettyJSON(res.Blobs), prettyJSON(want)
1354 t.Fatalf("Query %d: Got blobs:\n%s\nWant:\n%s\n", i+1, gotj, wantj)
1355 }
1356 contToken = res.Continue
1357 haveToken := contToken != ""
1358 wantHaveToken := (i + 1) < len(tests)
1359 if haveToken != wantHaveToken {
1360 t.Fatalf("Query %d: token = %q; want token = %v", i+1, contToken, wantHaveToken)
1361 }
1362 }
1363 })
1364}

Calls 9

ByRefTypeAlias · 0.92
testQueryTypesFunction · 0.85
prettyJSONFunction · 0.85
NewPlannedPermanodeMethod · 0.80
LogfMethod · 0.80
HandlerMethod · 0.80
QueryMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected