Some checks failed
Go CI/CD / go-ci (push) Failing after 6m59s
Introduce unit tests to verify the string and color outputs of StoneLevel. These tests ensure the correct mapping of log levels to their respective string values and color codes.
48 lines
872 B
Go
48 lines
872 B
Go
package stonelog
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func Test_LogLevelString(t *testing.T) {
|
|
levelTests := []struct {
|
|
level StoneLevel
|
|
expected string
|
|
}{
|
|
{TRACE, "TRACE"},
|
|
{DEBUG, "DEBUG"},
|
|
{INFO, "INFO"},
|
|
{WARN, "WARN"},
|
|
{ERROR, "ERROR"},
|
|
{FATAL, "FATAL"},
|
|
{PANIC, "PANIC"},
|
|
}
|
|
|
|
for _, tt := range levelTests {
|
|
if tt.level.String() != tt.expected {
|
|
t.Errorf("Expected %s, got %s", tt.expected, tt.level.String())
|
|
}
|
|
}
|
|
}
|
|
|
|
func Test_LogLevelColor(t *testing.T) {
|
|
levelTests := []struct {
|
|
level StoneLevel
|
|
expected string
|
|
}{
|
|
{TRACE, colorWhite},
|
|
{DEBUG, colorCyan},
|
|
{INFO, colorGreen},
|
|
{WARN, colorYellow},
|
|
{ERROR, colorRed},
|
|
{FATAL, colorMagenta},
|
|
{PANIC, colorRed + "\033[1m"},
|
|
}
|
|
|
|
for _, tt := range levelTests {
|
|
if tt.level.Color() != tt.expected {
|
|
t.Errorf("Expected %s, got %s", tt.expected, tt.level.Color())
|
|
}
|
|
}
|
|
}
|