mirror of
https://github.com/lukaszraczylo/semver-generator.git
synced 2026-06-10 23:28:58 +00:00
Refactor the code to use more modular and testable approach.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestInitLogger(t *testing.T) {
|
||||
// Test with debug mode enabled
|
||||
logger := InitLogger(true)
|
||||
assert.NotNil(t, logger, "Logger should not be nil")
|
||||
assert.NotNil(t, Logger, "Global logger should not be nil")
|
||||
|
||||
// Test with debug mode disabled
|
||||
logger = InitLogger(false)
|
||||
assert.NotNil(t, logger, "Logger should not be nil")
|
||||
assert.NotNil(t, Logger, "Global logger should not be nil")
|
||||
}
|
||||
|
||||
func TestLoggingFunctions(t *testing.T) {
|
||||
// Initialize logger with debug mode
|
||||
InitLogger(true)
|
||||
|
||||
// Just test that these don't panic
|
||||
Debug("Debug message", map[string]interface{}{"key": "value"})
|
||||
Info("Info message", map[string]interface{}{"key": "value"})
|
||||
Error("Error message", map[string]interface{}{"key": "value"})
|
||||
|
||||
// Skip testing Critical as it might call os.Exit
|
||||
// Critical("Critical message", map[string]interface{}{"key": "value"})
|
||||
|
||||
// Test passes if we get here without panicking
|
||||
assert.True(t, true)
|
||||
}
|
||||
|
||||
func TestLoggingWithNilLogger(t *testing.T) {
|
||||
// Temporarily set logger to nil
|
||||
oldLogger := Logger
|
||||
Logger = nil
|
||||
defer func() { Logger = oldLogger }()
|
||||
|
||||
// These should not panic
|
||||
Debug("Debug message", map[string]interface{}{"key": "value"})
|
||||
Info("Info message", map[string]interface{}{"key": "value"})
|
||||
Error("Error message", map[string]interface{}{"key": "value"})
|
||||
|
||||
// Skip testing Critical as it might call os.Exit
|
||||
// Critical("Critical message", map[string]interface{}{"key": "value"})
|
||||
|
||||
// Test passes if we get here without panicking
|
||||
assert.True(t, true)
|
||||
}
|
||||
Reference in New Issue
Block a user