(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…