|
1 | 1 | package syslog |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "net" |
5 | | - "testing" |
6 | | - "time" |
| 4 | + "net" |
| 5 | + "testing" |
| 6 | + "time" |
7 | 7 | ) |
8 | 8 |
|
9 | 9 | func TestMessageNetSrc(t *testing.T) { |
10 | | - tcpAddress, err := net.ResolveTCPAddr("tcp", "localhost:1234") |
| 10 | + tcpAddress, err := net.ResolveTCPAddr("tcp", "localhost:1234") |
11 | 11 |
|
12 | | - if err != nil { |
13 | | - t.Errorf("could not resolve TCP address") |
14 | | - } |
| 12 | + if err != nil { |
| 13 | + t.Errorf("could not resolve TCP address") |
| 14 | + } |
15 | 15 |
|
16 | | - m := &Message{time.Now(), tcpAddress, 0, 0, time.Now(), "", "", "", "", ""} |
17 | | - if m.NetSrc() != "127.0.0.1" { |
18 | | - t.Errorf("expected 127.0.0.1, got ", m.NetSrc()) |
19 | | - } |
| 16 | + m := &Message{time.Now(), tcpAddress, 0, 0, time.Now(), "", "", "", "", ""} |
| 17 | + if m.NetSrc() != "127.0.0.1" { |
| 18 | + t.Errorf("expected 127.0.0.1, got ", m.NetSrc()) |
| 19 | + } |
20 | 20 |
|
21 | | - udpAddress, err := net.ResolveUDPAddr("udp", "localhost:1234") |
| 21 | + udpAddress, err := net.ResolveUDPAddr("udp", "localhost:1234") |
22 | 22 |
|
23 | | - if err != nil { |
24 | | - t.Errorf("could not resolve UDP address") |
25 | | - } |
| 23 | + if err != nil { |
| 24 | + t.Errorf("could not resolve UDP address") |
| 25 | + } |
26 | 26 |
|
27 | | - m.Source = udpAddress |
28 | | - if m.NetSrc() != "127.0.0.1" { |
29 | | - t.Errorf("expected 127.0.0.1, got ", m.NetSrc()) |
30 | | - } |
| 27 | + m.Source = udpAddress |
| 28 | + if m.NetSrc() != "127.0.0.1" { |
| 29 | + t.Errorf("expected 127.0.0.1, got ", m.NetSrc()) |
| 30 | + } |
31 | 31 |
|
32 | | - unixAddress, err := net.ResolveUnixAddr("unix", "/tmp/str") |
| 32 | + unixAddress, err := net.ResolveUnixAddr("unix", "/tmp/str") |
33 | 33 |
|
34 | | - if err != nil { |
35 | | - t.Errorf("could not resolve unix address") |
36 | | - } |
| 34 | + if err != nil { |
| 35 | + t.Errorf("could not resolve unix address") |
| 36 | + } |
37 | 37 |
|
38 | | - m.Source = unixAddress |
39 | | - if m.NetSrc() != "/tmp/str" { |
40 | | - t.Errorf("expected /tmp/str, got ", m.NetSrc()) |
41 | | - } |
| 38 | + m.Source = unixAddress |
| 39 | + if m.NetSrc() != "/tmp/str" { |
| 40 | + t.Errorf("expected /tmp/str, got ", m.NetSrc()) |
| 41 | + } |
42 | 42 |
|
43 | | - unknownAddress, err := net.ResolveIPAddr("ip4", "localhost") |
| 43 | + unknownAddress, err := net.ResolveIPAddr("ip4", "localhost") |
44 | 44 |
|
45 | | - if err != nil { |
46 | | - t.Errorf("could not resolve unknown address") |
47 | | - } |
| 45 | + if err != nil { |
| 46 | + t.Errorf("could not resolve unknown address") |
| 47 | + } |
48 | 48 |
|
49 | | - m.Source = unknownAddress |
50 | | - if m.NetSrc() != "127.0.0.1" { |
51 | | - t.Errorf("expected 127.0.0.1, got ", m.NetSrc()) |
52 | | - } |
| 49 | + m.Source = unknownAddress |
| 50 | + if m.NetSrc() != "127.0.0.1" { |
| 51 | + t.Errorf("expected 127.0.0.1, got ", m.NetSrc()) |
| 52 | + } |
53 | 53 | } |
54 | 54 |
|
55 | 55 | func TestMessageFormat(t *testing.T) { |
56 | | - tcpAddress, err := net.ResolveTCPAddr("tcp", "localhost:1234") |
57 | | - |
58 | | - if err != nil { |
59 | | - t.Errorf("could not resolve TCP address") |
60 | | - } |
61 | | - |
62 | | - m := &Message{ |
63 | | - time.Now(), |
64 | | - tcpAddress, |
65 | | - 0, |
66 | | - 0, |
67 | | - time.Now(), |
68 | | - "localhost", |
69 | | - "TEST", |
70 | | - "hello world", |
71 | | - "", |
72 | | - "", |
73 | | - } |
74 | | - |
75 | | - timeLayout := "2006-01-02 15:04:05" |
76 | | - expectedOutput := m.Time.Format(timeLayout) + " localhost hello world" |
77 | | - if m.String() != expectedOutput { |
78 | | - t.Errorf("expected '" + expectedOutput + "', got '" + m.String() + "'.") |
79 | | - } |
| 56 | + tcpAddress, err := net.ResolveTCPAddr("tcp", "localhost:1234") |
| 57 | + |
| 58 | + if err != nil { |
| 59 | + t.Errorf("could not resolve TCP address") |
| 60 | + } |
| 61 | + |
| 62 | + m := &Message{ |
| 63 | + time.Now(), |
| 64 | + tcpAddress, |
| 65 | + 0, |
| 66 | + 0, |
| 67 | + time.Now(), |
| 68 | + "localhost", |
| 69 | + "TEST", |
| 70 | + "hello world", |
| 71 | + "", |
| 72 | + "", |
| 73 | + } |
| 74 | + |
| 75 | + timeLayout := "2006-01-02 15:04:05" |
| 76 | + expectedOutput := m.Time.Format(timeLayout) + " localhost TESThello world" |
| 77 | + if m.String() != expectedOutput { |
| 78 | + t.Errorf("expected '" + expectedOutput + "', got '" + m.String() + "'.") |
| 79 | + } |
80 | 80 | } |
0 commit comments