gologger/format_test.go

45 lines
934 B
Go
Raw Normal View History

2024-10-01 13:47:50 +08:00
package gologger
import (
"strings"
"testing"
"time"
)
func TestFormat(t *testing.T) {
tests := []struct {
name string
logEvent LogEvent
want string
}{
{
name: "Info level with format string",
logEvent: LogEvent{
Ts: time.Now(),
Category: "test_category",
Level: Info,
Data: []interface{}{"%s: %v", "key", "value"},
},
want: "test_category : INFO - key: value",
},
{
name: "Error level without format string",
logEvent: LogEvent{
Ts: time.Now(),
Category: "test_category",
Level: Error,
Data: []interface{}{"error occurred", "additional info"},
},
want: "test_category : ERROR - error occurred additional info",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := format(tt.logEvent); strings.Index(got, tt.want) == -1 {
t.Errorf("format() = %v, want %v", got, tt.want)
}
})
}
}