1
0
mirror of https://github.com/Luzifer/elb-instance-status.git synced 2024-09-19 15:12:57 +00:00
elb-instance-status/prefixed_logger_test.go

35 lines
810 B
Go
Raw Normal View History

package main
import (
"bytes"
"testing"
)
func TestPrefixedLogger(t *testing.T) {
var (
buf = bytes.NewBuffer([]byte{})
pl = newPrefixedLogger(buf, "baum")
n int
err error
)
n, err = pl.Write([]byte("non-newline terminated string"))
if n != 29 || err != nil {
t.Fatalf("Write to prefixedLogger had unexpected results: n=29 != %d, err=nil != %s", n, err)
}
if n = len(buf.Bytes()); n != 0 {
t.Fatalf("Buffer contains %d characters, should contain 0", n)
}
pl.Write([]byte("now a newline\nand something"))
if n = len(buf.Bytes()); n != 50 {
t.Fatalf("Buffer contains %d characters, should contain 50", n)
}
pl.Write([]byte(" more to log\nwith multiple\nnewlines\n"))
if n = len(buf.Bytes()); n != 120 {
t.Fatalf("Buffer contains %d characters, should contain 120", n)
}
}