-
Notifications
You must be signed in to change notification settings - Fork 0
/
syslog_test.go
60 lines (47 loc) · 995 Bytes
/
syslog_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2022
// Author: Jeff Weisberg <tcp4me.com!jaw>
// Created: 2022-Jul-24 10:41 (EDT)
// Function: test
package syslog
import (
"fmt"
"testing"
"time"
)
func TestSyslog(t *testing.T) {
l, err := New(
WithDst("udp", "localhost"),
WithHostname("localhost.example.com"),
WithAppName("test"),
WithProcessId("1234"),
WithFacilityName("uucp"))
if err != nil {
t.Fatalf("error: %v", err)
}
m := Message{
time: time.Unix(1, 0),
Message: "foo\nbar",
SData: []*Structured{
{
Name: "Foo",
Enterprise: "32473",
Param: map[string]string{
"girth": "foo\\bar]s",
},
},
},
}
pkt, err := l.marshal(SevInfo, &m)
if err != nil {
t.Fatalf("error: %v", err)
}
exp := `<70>1 1970-01-01T00:00:01Z localhost.example.com test 1234 - [Foo@32473 girth="foo\\bar\]s"] foo bar`
if pkt != exp {
fmt.Printf(">> %s\n!= %s\n", pkt, exp)
t.Fail()
}
err = l.Send(SevInfo, m)
if err != nil {
t.Fatalf("error: %v", err)
}
}