MCPcopy
hub / github.com/pocketbase/pocketbase / TestBaseAppRefreshSettingsLoggerMinLevelEnabled

Function TestBaseAppRefreshSettingsLoggerMinLevelEnabled

core/base_test.go:333–402  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

331}
332
333func TestBaseAppRefreshSettingsLoggerMinLevelEnabled(t *testing.T) {
334 scenarios := []struct {
335 name string
336 isDev bool
337 level int
338 // level->enabled map
339 expectations map[int]bool
340 }{
341 {
342 "dev mode",
343 true,
344 4,
345 map[int]bool{
346 3: true,
347 4: true,
348 5: true,
349 },
350 },
351 {
352 "nondev mode",
353 false,
354 4,
355 map[int]bool{
356 3: false,
357 4: true,
358 5: true,
359 },
360 },
361 }
362
363 for _, s := range scenarios {
364 t.Run(s.name, func(t *testing.T) {
365 const testDataDir = "./pb_base_app_test_data_dir/"
366 defer os.RemoveAll(testDataDir)
367
368 app := core.NewBaseApp(core.BaseAppConfig{
369 DataDir: testDataDir,
370 IsDev: s.isDev,
371 })
372 defer app.ResetBootstrapState()
373
374 if err := app.Bootstrap(); err != nil {
375 t.Fatal(err)
376 }
377
378 // silence query logs
379 app.ConcurrentDB().(*dbx.DB).ExecLogFunc = func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) {}
380 app.ConcurrentDB().(*dbx.DB).QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {}
381 app.NonconcurrentDB().(*dbx.DB).ExecLogFunc = func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) {}
382 app.NonconcurrentDB().(*dbx.DB).QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {}
383
384 handler, ok := app.Logger().Handler().(*logger.BatchHandler)
385 if !ok {
386 t.Fatalf("Expected BatchHandler, got %v", app.Logger().Handler())
387 }
388
389 app.Settings().Logs.MinLevel = s.level
390

Callers

nothing calls this directly

Calls 11

ResetBootstrapStateMethod · 0.95
BootstrapMethod · 0.95
ConcurrentDBMethod · 0.95
NonconcurrentDBMethod · 0.95
LoggerMethod · 0.95
SettingsMethod · 0.95
SaveMethod · 0.95
NewBaseAppFunction · 0.92
EnabledMethod · 0.80
RunMethod · 0.45
RemoveAllMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…