MCPcopy
hub / github.com/pocketbase/pocketbase / TestBaseAppLoggerLevelDevPrint

Function TestBaseAppLoggerLevelDevPrint

core/log_printer_test.go:16–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestBaseAppLoggerLevelDevPrint(t *testing.T) {
17 testLogLevel := 4
18
19 scenarios := []struct {
20 name string
21 isDev bool
22 levels []int
23 printedLevels []int
24 persistedLevels []int
25 }{
26 {
27 "dev mode",
28 true,
29 []int{testLogLevel - 1, testLogLevel, testLogLevel + 1},
30 []int{testLogLevel - 1, testLogLevel, testLogLevel + 1},
31 []int{testLogLevel, testLogLevel + 1},
32 },
33 {
34 "nondev mode",
35 false,
36 []int{testLogLevel - 1, testLogLevel, testLogLevel + 1},
37 []int{},
38 []int{testLogLevel, testLogLevel + 1},
39 },
40 }
41
42 for _, s := range scenarios {
43 t.Run(s.name, func(t *testing.T) {
44 const testDataDir = "./pb_base_app_test_data_dir/"
45 defer os.RemoveAll(testDataDir)
46
47 app := NewBaseApp(BaseAppConfig{
48 DataDir: testDataDir,
49 IsDev: s.isDev,
50 })
51 defer app.ResetBootstrapState()
52
53 if err := app.Bootstrap(); err != nil {
54 t.Fatal(err)
55 }
56
57 // silence query logs
58 app.concurrentDB.(*dbx.DB).ExecLogFunc = func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) {}
59 app.concurrentDB.(*dbx.DB).QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {}
60 app.nonconcurrentDB.(*dbx.DB).ExecLogFunc = func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) {}
61 app.nonconcurrentDB.(*dbx.DB).QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {}
62
63 app.Settings().Logs.MinLevel = testLogLevel
64 if err := app.Save(app.Settings()); err != nil {
65 t.Fatal(err)
66 }
67
68 var printedLevels []int
69 var persistedLevels []int
70
71 ctx := context.Background()
72
73 // track printed logs

Callers

nothing calls this directly

Calls 13

ResetBootstrapStateMethod · 0.95
BootstrapMethod · 0.95
SettingsMethod · 0.95
SaveMethod · 0.95
LoggerMethod · 0.95
ExistInSliceFunction · 0.92
NewBaseAppFunction · 0.85
WriteAllMethod · 0.80
NextMethod · 0.65
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…