test: add simple unit tests for backend and logging packages
Build / build (push) Successful in 31s

This commit is contained in:
2026-05-22 22:49:25 +02:00
parent b71072f6c8
commit 92b82da3af
5 changed files with 634 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
package logging
import (
"testing"
)
func TestGetLogger(t *testing.T) {
// Reset the global logger for this test
Logger = nil
result := GetLogger()
if result == nil {
t.Error("GetLogger() returned nil")
}
}
func TestGetLoggerMultipleCalls(t *testing.T) {
// Reset the global logger for this test
Logger = nil
logger1 := GetLogger()
logger2 := GetLogger()
if logger1 != logger2 {
t.Error("GetLogger() returned different instances on multiple calls")
}
}
func TestGetSugaredLogger(t *testing.T) {
// Reset the global sugared logger for this test
SugaredLogger = nil
result := GetSugaredLogger()
if result == nil {
t.Error("GetSugaredLogger() returned nil")
}
}
func TestGetSugaredLoggerMultipleCalls(t *testing.T) {
// Reset the global sugared logger for this test
SugaredLogger = nil
logger1 := GetSugaredLogger()
logger2 := GetSugaredLogger()
if logger1 != logger2 {
t.Error("GetSugaredLogger() returned different instances on multiple calls")
}
}
func TestInit(t *testing.T) {
// Test JSON output
Init("debug", true)
logger := GetLogger()
if logger == nil {
t.Error("Init with json output failed")
}
// Test console output
Init("info", false)
logger = GetLogger()
if logger == nil {
t.Error("Init with console output failed")
}
}
func TestInitInvalidLevel(t *testing.T) {
// Test with invalid log level - should default to info
Init("invalid_level", false)
logger := GetLogger()
if logger == nil {
t.Error("Init with invalid level failed")
}
}