Files
GiteaMailTemplates/tools/logging/logging_test.go
T
KenanZhu c93f2bf8b2
Release / Validate Templates (push) Successful in 2m55s
Release / Package & Release (push) Skipped
Release / Remind to Update Release Documentation (push) Skipped
chore: simplify workflows and unify tool logging and mail presentation
2026-10-10 14:54:40 +08:00

28 lines
655 B
Go

package logging
import (
"bytes"
"testing"
)
func TestFormat(t *testing.T) {
for _, tc := range []struct {
level, code string
}{{"I", "32"}, {"W", "33"}, {"E", "31"}, {"F", "35"}} {
t.Run(tc.level, func(t *testing.T) {
for _, color := range []bool{false, true} {
var buf bytes.Buffer
write(&buf, color, tc.level, "Builder", "first\r\nsecond\n")
label := "[" + tc.level + "]"
if color {
label = "\033[" + tc.code + "m" + label + "\033[0m"
}
want := label + " [Builder] first\n" + label + " [Builder] second\n"
if buf.String() != want {
t.Fatalf("got %q, want %q", buf.String(), want)
}
}
})
}
}