mysqlbinlog/parse_io_test.go

34 lines
873 B
Go
Raw Normal View History

package binlog
import (
"strings"
"testing"
)
func TestFormatBodyPreview(t *testing.T) {
if got := formatBodyPreview(nil, 256); got != "len=0" {
t.Fatalf("unexpected empty preview: %q", got)
}
small := []byte{0x01, 0x02, 0xAB}
got := formatBodyPreview(small, 8)
if !strings.Contains(got, "len=3") || !strings.Contains(got, "0102ab") {
t.Fatalf("unexpected preview for small body: %q", got)
}
if strings.Contains(got, "...") {
t.Fatalf("small body should not be truncated: %q", got)
}
large := make([]byte, 300)
for i := range large {
large[i] = byte(i)
}
got = formatBodyPreview(large, 16)
if !strings.Contains(got, "len=300") || !strings.Contains(got, "preview(hex,16B)=") {
t.Fatalf("unexpected preview for large body: %q", got)
}
if !strings.HasSuffix(got, "...") {
t.Fatalf("large body should be truncated with ellipsis: %q", got)
}
}