github.com/blystad/deis@v0.11.0/logger/syslog/message_test.go (about) 1 package syslog 2 3 import ( 4 "net" 5 "testing" 6 "time" 7 ) 8 9 func TestMessageNetSrc(t *testing.T) { 10 tcpAddress, err := net.ResolveTCPAddr("tcp", "localhost:1234") 11 12 if err != nil { 13 t.Error("could not resolve TCP address") 14 } 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 %s", m.NetSrc()) 19 } 20 21 udpAddress, err := net.ResolveUDPAddr("udp", "localhost:1234") 22 23 if err != nil { 24 t.Error("could not resolve UDP address") 25 } 26 27 m.Source = udpAddress 28 if m.NetSrc() != "127.0.0.1" { 29 t.Errorf("expected 127.0.0.1, got %s", m.NetSrc()) 30 } 31 32 unixAddress, err := net.ResolveUnixAddr("unix", "/tmp/str") 33 34 if err != nil { 35 t.Error("could not resolve unix address") 36 } 37 38 m.Source = unixAddress 39 if m.NetSrc() != "/tmp/str" { 40 t.Errorf("expected /tmp/str, got %s", m.NetSrc()) 41 } 42 43 unknownAddress, err := net.ResolveIPAddr("ip4", "localhost") 44 45 if err != nil { 46 t.Error("could not resolve unknown address") 47 } 48 49 m.Source = unknownAddress 50 if m.NetSrc() != "127.0.0.1" { 51 t.Errorf("expected 127.0.0.1, got %s", m.NetSrc()) 52 } 53 } 54 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 TESThello world" 77 if m.String() != expectedOutput { 78 t.Errorf("expected '" + expectedOutput + "', got '" + m.String() + "'.") 79 } 80 }