feat: harden runtime import and frontend verification workflows
This commit is contained in:
@@ -12,7 +12,7 @@ func TestInit(t *testing.T) {
|
||||
defer func() { logger = oldLogger }()
|
||||
|
||||
Init()
|
||||
|
||||
|
||||
if logger == nil {
|
||||
t.Error("logger should not be nil after Init")
|
||||
}
|
||||
@@ -21,7 +21,7 @@ func TestInit(t *testing.T) {
|
||||
func TestInitWithLevel(t *testing.T) {
|
||||
// Test different levels
|
||||
levels := []string{"DEBUG", "INFO", "WARN", "ERROR", "unknown"}
|
||||
|
||||
|
||||
for _, level := range levels {
|
||||
InitWithLevel(level)
|
||||
if logger == nil {
|
||||
@@ -46,7 +46,7 @@ func TestParseLevel(t *testing.T) {
|
||||
{"unknown", slog.LevelInfo},
|
||||
{"", slog.LevelInfo},
|
||||
}
|
||||
|
||||
|
||||
for _, test := range tests {
|
||||
result := parseLevel(test.input)
|
||||
if result != test.expected {
|
||||
@@ -64,19 +64,19 @@ func TestIsSensitive(t *testing.T) {
|
||||
"access_token",
|
||||
"PRIVATE_KEY",
|
||||
}
|
||||
|
||||
|
||||
for _, field := range sensitive {
|
||||
if !IsSensitive(field) {
|
||||
t.Errorf("IsSensitive(%q) should be true", field)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
notSensitive := []string{
|
||||
"name",
|
||||
"email",
|
||||
"user_id",
|
||||
}
|
||||
|
||||
|
||||
for _, field := range notSensitive {
|
||||
if IsSensitive(field) {
|
||||
t.Errorf("IsSensitive(%q) should be false", field)
|
||||
@@ -96,7 +96,7 @@ func TestSanitizeAttrs(t *testing.T) {
|
||||
{"secret_key", "xyz789", "[REDACTED]"},
|
||||
{"name", "test", "test"},
|
||||
}
|
||||
|
||||
|
||||
for _, test := range tests {
|
||||
attr := slog.String(test.key, test.value)
|
||||
result := sanitizeAttrs(nil, attr)
|
||||
@@ -109,7 +109,7 @@ func TestSanitizeAttrs(t *testing.T) {
|
||||
func TestLoggingMethods(t *testing.T) {
|
||||
// Just verify methods don't panic
|
||||
Init()
|
||||
|
||||
|
||||
Info("test info message", "key", "value")
|
||||
Debug("test debug message", "key", "value")
|
||||
Warn("test warn message", "key", "value")
|
||||
@@ -138,7 +138,7 @@ func TestInitWithConfig(t *testing.T) {
|
||||
cfg.Output = "stdout"
|
||||
cfg.Level = "DEBUG"
|
||||
InitWithConfig(cfg)
|
||||
|
||||
|
||||
if logger == nil {
|
||||
t.Error("logger should not be nil after InitWithConfig")
|
||||
}
|
||||
@@ -151,9 +151,9 @@ func TestInitWithConfigFileOutput(t *testing.T) {
|
||||
cfg.Output = tmpFile
|
||||
cfg.Rotation = false
|
||||
InitWithConfig(cfg)
|
||||
|
||||
|
||||
Info("test message for file")
|
||||
|
||||
|
||||
// Verify file was created
|
||||
if _, err := os.Stat(tmpFile); os.IsNotExist(err) {
|
||||
t.Errorf("log file %s should exist", tmpFile)
|
||||
@@ -162,27 +162,27 @@ func TestInitWithConfigFileOutput(t *testing.T) {
|
||||
|
||||
func TestDefaultConfig(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
|
||||
|
||||
if cfg.Level != "INFO" {
|
||||
t.Errorf("default Level = %s, want INFO", cfg.Level)
|
||||
}
|
||||
|
||||
|
||||
if cfg.Output != "stdout" {
|
||||
t.Errorf("default Output = %s, want stdout", cfg.Output)
|
||||
}
|
||||
|
||||
|
||||
if cfg.MaxSize != 100 {
|
||||
t.Errorf("default MaxSize = %d, want 100", cfg.MaxSize)
|
||||
}
|
||||
|
||||
|
||||
if cfg.MaxBackups != 3 {
|
||||
t.Errorf("default MaxBackups = %d, want 3", cfg.MaxBackups)
|
||||
}
|
||||
|
||||
|
||||
if cfg.MaxAge != 7 {
|
||||
t.Errorf("default MaxAge = %d, want 7", cfg.MaxAge)
|
||||
}
|
||||
|
||||
|
||||
if !cfg.Compress {
|
||||
t.Error("default Compress should be true")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user