39 lines
716 B
Go
39 lines
716 B
Go
|
package journal
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"encoding/hex"
|
||
|
"net"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestWireWrite(t *testing.T) {
|
||
|
var buf net.Buffers
|
||
|
out := bytes.NewBuffer(nil)
|
||
|
err := WireWrite(&buf, out, []Attr{
|
||
|
Attr{
|
||
|
Key: AttrKey{key: "MESSAGE"},
|
||
|
Value: []byte("hello, world!"),
|
||
|
},
|
||
|
priorityAttrMap[PriDebug],
|
||
|
Attr{
|
||
|
Key: AttrKey{key: "MULTI_LINE"},
|
||
|
Value: []byte("hello,\nworld!"),
|
||
|
},
|
||
|
})
|
||
|
if err != nil {
|
||
|
t.Errorf("unexpected error writing to buffer: %v", err)
|
||
|
}
|
||
|
|
||
|
if out.String() != wireWriteExpected {
|
||
|
t.Error("unexpected output buffer:\n" + hex.Dump(out.Bytes()))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const wireWriteExpected = `MESSAGE=hello, world!
|
||
|
PRIORITY=7
|
||
|
MULTI_LINE
|
||
|
` + "\x0D\x00\x00\x00\x00\x00\x00\x00" + `hello,
|
||
|
world!
|
||
|
`
|