MCPcopy
hub / github.com/pocketbase/pocketbase / TestFindCachedCollectionReferences

Function TestFindCachedCollectionReferences

core/collection_query_test.go:263–342  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

261}
262
263func TestFindCachedCollectionReferences(t *testing.T) {
264 t.Parallel()
265
266 app, _ := tests.NewTestApp()
267 defer app.Cleanup()
268
269 collection, err := app.FindCollectionByNameOrId("demo3")
270 if err != nil {
271 t.Fatal(err)
272 }
273
274 totalQueries := 0
275 app.ConcurrentDB().(*dbx.DB).QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {
276 totalQueries++
277 }
278
279 run := func(withCache bool) {
280 var expectedTotalQueries int
281
282 if withCache {
283 err := app.ReloadCachedCollections()
284 if err != nil {
285 t.Fatal(err)
286 }
287 } else {
288 app.Store().Reset(nil)
289 expectedTotalQueries = 1
290 }
291
292 totalQueries = 0
293
294 result, err := app.FindCachedCollectionReferences(
295 collection,
296 collection.Id,
297 // test whether "nonempty" exclude ids condition will be skipped
298 "",
299 "",
300 )
301 if err != nil {
302 t.Fatal(err)
303 }
304
305 if len(result) != 1 {
306 t.Fatalf("Expected 1 collection, got %d: %v", len(result), result)
307 }
308
309 expectedFields := []string{
310 "rel_one_no_cascade",
311 "rel_one_no_cascade_required",
312 "rel_one_cascade",
313 "rel_one_unique",
314 "rel_many_no_cascade",
315 "rel_many_no_cascade_required",
316 "rel_many_cascade",
317 "rel_many_unique",
318 }
319
320 for col, fields := range result {

Callers

nothing calls this directly

Calls 9

CleanupMethod · 0.95
NewTestAppFunction · 0.92
ConcurrentDBMethod · 0.65
StoreMethod · 0.65
GetNameMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…