(t *testing.T, sortType SortType, source string)
| 1147 | } |
| 1148 | |
| 1149 | func testQueryRecentPermanodes(t *testing.T, sortType SortType, source string) { |
| 1150 | testQueryTypes(t, memIndexTypes, func(qt *queryTest) { |
| 1151 | id := qt.id |
| 1152 | |
| 1153 | p1 := id.NewPlannedPermanode("1") |
| 1154 | id.SetAttribute(p1, "foo", "p1") |
| 1155 | p2 := id.NewPlannedPermanode("2") |
| 1156 | id.SetAttribute(p2, "foo", "p2") |
| 1157 | p3 := id.NewPlannedPermanode("3") |
| 1158 | id.SetAttribute(p3, "foo", "p3") |
| 1159 | |
| 1160 | var usedSource string |
| 1161 | ExportSetCandidateSourceHook(func(s string) { |
| 1162 | usedSource = s |
| 1163 | }) |
| 1164 | |
| 1165 | req := &SearchQuery{ |
| 1166 | Constraint: &Constraint{ |
| 1167 | Permanode: &PermanodeConstraint{}, |
| 1168 | }, |
| 1169 | Limit: 2, |
| 1170 | Sort: sortType, |
| 1171 | Describe: &DescribeRequest{}, |
| 1172 | } |
| 1173 | handler := qt.Handler() |
| 1174 | res, err := handler.Query(ctxbg, req) |
| 1175 | if err != nil { |
| 1176 | qt.t.Fatal(err) |
| 1177 | } |
| 1178 | if usedSource != source { |
| 1179 | t.Errorf("used candidate source strategy %q; want %v", usedSource, source) |
| 1180 | } |
| 1181 | wantBlobs := []*SearchResultBlob{ |
| 1182 | {Blob: p3}, |
| 1183 | {Blob: p2}, |
| 1184 | } |
| 1185 | if !reflect.DeepEqual(res.Blobs, wantBlobs) { |
| 1186 | gotj, wantj := prettyJSON(res.Blobs), prettyJSON(wantBlobs) |
| 1187 | t.Errorf("Got blobs:\n%s\nWant:\n%s\n", gotj, wantj) |
| 1188 | } |
| 1189 | if got := len(res.Describe.Meta); got != 2 { |
| 1190 | t.Errorf("got %d described blobs; want 2", got) |
| 1191 | } |
| 1192 | |
| 1193 | // And test whether continue (for infinite scroll) works: |
| 1194 | { |
| 1195 | if got, want := res.Continue, "pn:1322443958000123456:sha224-e1bd2812721791c0d087778220fa307e059da6501a1a4fd7a9f34703"; got != want { |
| 1196 | t.Fatalf("Continue token = %q; want %q", got, want) |
| 1197 | } |
| 1198 | req := &SearchQuery{ |
| 1199 | Constraint: &Constraint{ |
| 1200 | Permanode: &PermanodeConstraint{}, |
| 1201 | }, |
| 1202 | Limit: 2, |
| 1203 | Sort: sortType, |
| 1204 | Continue: res.Continue, |
| 1205 | } |
| 1206 | res, err := handler.Query(ctxbg, req) |
no test coverage detected