feat: colorize http status logs
This commit is contained in:
@@ -34,3 +34,27 @@ func TestFormatLogEntryFormatsHTTPRequestCompactly(t *testing.T) {
|
||||
t.Fatalf("line should omit loopback ip: %q", line)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatHTTPStatusColorsByStatusFamily(t *testing.T) {
|
||||
previousColorLogs := colorLogs
|
||||
colorLogs = true
|
||||
t.Cleanup(func() {
|
||||
colorLogs = previousColorLogs
|
||||
})
|
||||
|
||||
tests := map[any]string{
|
||||
101: ansiStatusBlue + "101" + ansiReset,
|
||||
200: ansiGreen + "200" + ansiReset,
|
||||
302: ansiYellow + "302" + ansiReset,
|
||||
404: ansiOrange + "404" + ansiReset,
|
||||
500: ansiRed + "500" + ansiReset,
|
||||
"unknown": "unknown",
|
||||
}
|
||||
|
||||
for input, want := range tests {
|
||||
got := formatHTTPStatus(input)
|
||||
if got != want {
|
||||
t.Fatalf("formatHTTPStatus(%v) = %q, want %q", input, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user