-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmessage_test.go
More file actions
80 lines (63 loc) · 1.6 KB
/
message_test.go
File metadata and controls
80 lines (63 loc) · 1.6 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package syslog
import (
"net"
"testing"
"time"
)
func TestMessageNetSrc(t *testing.T) {
tcpAddress, err := net.ResolveTCPAddr("tcp", "localhost:1234")
if err != nil {
t.Error("could not resolve TCP address")
}
m := &Message{time.Now(), tcpAddress, 0, 0, time.Now(), "", "", "", "", ""}
if m.NetSrc() != "127.0.0.1" {
t.Errorf("expected 127.0.0.1, got %s", m.NetSrc())
}
udpAddress, err := net.ResolveUDPAddr("udp", "localhost:1234")
if err != nil {
t.Error("could not resolve UDP address")
}
m.Source = udpAddress
if m.NetSrc() != "127.0.0.1" {
t.Errorf("expected 127.0.0.1, got %s", m.NetSrc())
}
unixAddress, err := net.ResolveUnixAddr("unix", "/tmp/str")
if err != nil {
t.Error("could not resolve unix address")
}
m.Source = unixAddress
if m.NetSrc() != "/tmp/str" {
t.Errorf("expected /tmp/str, got %s", m.NetSrc())
}
unknownAddress, err := net.ResolveIPAddr("ip4", "localhost")
if err != nil {
t.Error("could not resolve unknown address")
}
m.Source = unknownAddress
if m.NetSrc() != "127.0.0.1" {
t.Errorf("expected 127.0.0.1, got %s", m.NetSrc())
}
}
func TestMessageFormat(t *testing.T) {
tcpAddress, err := net.ResolveTCPAddr("tcp", "localhost:1234")
if err != nil {
t.Errorf("could not resolve TCP address")
}
m := &Message{
time.Now(),
tcpAddress,
0,
0,
time.Now(),
"localhost",
"TEST",
"hello world",
"",
"",
}
timeLayout := "2006-01-02 15:04:05"
expectedOutput := m.Time.Format(timeLayout) + " localhost TESThello world"
if m.String() != expectedOutput {
t.Errorf("expected '" + expectedOutput + "', got '" + m.String() + "'.")
}
}