diff --git a/pkg/observability/logging/level/level_test.go b/pkg/observability/logging/level/level_test.go new file mode 100644 index 000000000..05895e1b6 --- /dev/null +++ b/pkg/observability/logging/level/level_test.go @@ -0,0 +1,14 @@ +package level + +import "testing" + +func TestGetLevelID(t *testing.T) { + id := GetLevelID("invalid") + if id != 0 { + t.Errorf("expected %d got %d", 0, id) + } + id = GetLevelID(Info) + if id != InfoID { + t.Errorf("expected %d got %d", InfoID, id) + } +} diff --git a/pkg/observability/logging/logging_test.go b/pkg/observability/logging/logging_test.go index d82f01ced..012ca6833 100644 --- a/pkg/observability/logging/logging_test.go +++ b/pkg/observability/logging/logging_test.go @@ -68,7 +68,7 @@ func TestNewLogger_LogFile(t *testing.T) { logger.SetLogAsynchronous(false) logger.Info("testEntry ", Pairs{"testKey": "test Val", "testKey2": "testValue2"}) if _, err := os.Stat(instanceFileName); err != nil { - t.Errorf(err.Error()) + t.Error(err) } logger.Close() } @@ -83,7 +83,7 @@ func TestNewLoggerDebug_LogFile(t *testing.T) { logger.SetLogAsynchronous(false) logger.Debug("test entry", Pairs{"testKey": "testVal"}) if _, err := os.Stat(fileName); err != nil { - t.Errorf(err.Error()) + t.Error(err) } logger.Close() } @@ -98,7 +98,7 @@ func TestNewLoggerWarn_LogFile(t *testing.T) { logger.SetLogAsynchronous(false) logger.Warn("test entry", Pairs{"testKey": "testVal"}) if _, err := os.Stat(fileName); err != nil { - t.Errorf(err.Error()) + t.Error(err) } logger.Close() } @@ -108,7 +108,7 @@ func TestNewLoggerWarnOnce_LogFile(t *testing.T) { // it should create a logger that outputs to a log file ("out.test.log") conf := config.NewConfig() conf.Main = &config.MainConfig{InstanceID: 0} - conf.Logging = &options.Options{LogFile: fileName, LogLevel: "x"} + conf.Logging = &options.Options{LogFile: fileName, LogLevel: "info"} logger := New(conf) logger.SetLogAsynchronous(false) key := "warnonce-test-key" @@ -136,9 +136,10 @@ func TestNewLoggerWarnOnce_LogFile(t *testing.T) { } if _, err := os.Stat(fileName); err != nil { - t.Errorf(err.Error()) + t.Error(err) } logger.Close() + os.Remove(fileName) } func TestNewLoggerError_LogFile(t *testing.T) { @@ -151,7 +152,7 @@ func TestNewLoggerError_LogFile(t *testing.T) { logger.SetLogAsynchronous(false) logger.Error("test entry", Pairs{"testKey": "testVal"}) if _, err := os.Stat(fileName); err != nil { - t.Errorf(err.Error()) + t.Error(err) } logger.Close() } @@ -176,7 +177,7 @@ func TestNewLoggerErrorOnce_LogFile(t *testing.T) { } if _, err := os.Stat(fileName); err != nil { - t.Errorf(err.Error()) + t.Error(err) } logger.Close() } @@ -191,7 +192,7 @@ func TestNewLoggerDefault_LogFile(t *testing.T) { logger.SetLogAsynchronous(false) logger.Info("test entry", Pairs{"testKey": "testVal"}) if _, err := os.Stat(fileName); err != nil { - t.Errorf(err.Error()) + t.Error(err) } logger.Close() } @@ -215,7 +216,7 @@ func TestNewLoggerInfoOnce_LogFile(t *testing.T) { } if _, err := os.Stat(fileName); err != nil { - t.Errorf(err.Error()) + t.Error(err) } logger.Close() @@ -231,7 +232,7 @@ func TestNewLoggerFatal_LogFile(t *testing.T) { logger.SetLogAsynchronous(false) logger.Fatal(-1, "test entry", Pairs{"testKey": "testVal"}) if _, err := os.Stat(fileName); err != nil { - t.Errorf(err.Error()) + t.Error(err) } logger.Close() } diff --git a/pkg/proxy/engines/access_logs_test.go b/pkg/proxy/engines/access_logs_test.go index 566182eb1..41815f76e 100644 --- a/pkg/proxy/engines/access_logs_test.go +++ b/pkg/proxy/engines/access_logs_test.go @@ -37,7 +37,7 @@ func TestLogUpstreamRequest(t *testing.T) { logUpstreamRequest(logger, "testBackend", "testType", "testHandler", "testMethod", "testPath", "testUserAgent", 200, 0, 1.0) if _, err := os.Stat(fileName); err != nil { - t.Errorf(err.Error()) + t.Error(err) } logger.Close() } @@ -58,7 +58,7 @@ func TestLogDownstreamRequest(t *testing.T) { logDownstreamRequest(logger, r) if _, err := os.Stat(fileName); err != nil { - t.Errorf(err.Error()) + t.Error(err) } logger.Close() }