package app import ( "bytes" "strings" "testing" "github.com/phishingclub/phishingclub/config" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) // TestWarnExperimentalEngine checks that postgres logs the experimental // warning once and sqlite logs nothing func TestWarnExperimentalEngine(t *testing.T) { for _, tc := range []struct { engine string want int }{ {config.DatabaseEngineSQLite, 0}, {config.DatabaseEnginePostgres, 1}, } { t.Run(tc.engine, func(t *testing.T) { var buf bytes.Buffer core := zapcore.NewCore( zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), zapcore.AddSync(&buf), zapcore.DebugLevel, ) conf := config.NewProductionDefaultConfig() conf.SetDatabaseEngine(tc.engine) warnExperimentalEngine(zap.New(core).Sugar(), conf) out := buf.String() if got := strings.Count(out, experimentalEngineWarning); got != tc.want { t.Fatalf("got %d warnings, want %d: %s", got, tc.want, out) } if tc.want == 1 && !strings.Contains(out, `"level":"warn"`) { t.Fatalf("not logged as a warning: %s", out) } }) } }