mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-11-14 08:17:26 +01:00
24 lines
679 B
Go
24 lines
679 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoggingThreshold(t *testing.T) {
|
|
original := slog.Default()
|
|
defer slog.SetDefault(original)
|
|
for _, row := range []struct {
|
|
env, level string
|
|
want slog.Level
|
|
}{{"production", "", slog.LevelInfo}, {"development", "", slog.LevelDebug}, {"production", "WARN", slog.LevelWarn}, {"production", "error", slog.LevelError}, {"production", "invalid", slog.LevelInfo}} {
|
|
t.Setenv("NODE_ENV", row.env)
|
|
t.Setenv("LOG_LEVEL", row.level)
|
|
configureLogging()
|
|
if !slog.Default().Enabled(context.Background(), row.want) || slog.Default().Enabled(context.Background(), row.want-1) {
|
|
t.Fatal(row)
|
|
}
|
|
}
|
|
}
|