package logging import ( "testing" "github.com/rs/zerolog" . "github.com/yusing/go-proxy/internal/utils/testing" ) func TestFormatHTML(t *testing.T) { buf := make([]byte, 0, 100) buf = FormatLogEntryHTML(zerolog.InfoLevel, "This is a test.\nThis is a new line.", buf) ExpectEqual(t, string(buf), `
01-01 01:01 INF`) } func TestFormatHTMLANSI(t *testing.T) { buf := make([]byte, 0, 100) buf = FormatLogEntryHTML(zerolog.InfoLevel, "This is \x1b[91m\x1b[1ma test.\x1b[0mOK!.", buf) ExpectEqual(t, string(buf), `
01-01 01:01 INF`) buf = buf[:0] buf = FormatLogEntryHTML(zerolog.InfoLevel, "This is \x1b[91ma \x1b[1mtest.\x1b[0mOK!.", buf) ExpectEqual(t, string(buf), `
01-01 01:01 INF`) } func BenchmarkFormatLogEntryHTML(b *testing.B) { buf := make([]byte, 0, 100) for range b.N { FormatLogEntryHTML(zerolog.InfoLevel, "This is \x1b[91ma \x1b[1mtest.\x1b[0mOK!.", buf) } }