diff --git a/hooks/papertrail/papertrail_test.go b/hooks/papertrail/papertrail_test.go index a52874c..96318d0 100644 --- a/hooks/papertrail/papertrail_test.go +++ b/hooks/papertrail/papertrail_test.go @@ -1,43 +1,26 @@ package logrus_papertrail import ( - "net" + "fmt" "testing" "github.com/Sirupsen/logrus" + "github.com/stvp/go-udp-testing" ) func TestWritingToUDP(t *testing.T) { - log := logrus.New() port := 16661 - - addr := net.UDPAddr{ - Port: port, - IP: net.ParseIP("127.0.0.1"), - } - - c, err := net.ListenUDP("udp", &addr) - if err != nil { - t.Fatalf("ListenUDP failed: %v", err) - } - defer c.Close() + udp.SetAddr(fmt.Sprintf(":%d", port)) hook, err := NewPapertrailHook("localhost", port, "test") if err != nil { t.Errorf("Unable to connect to local UDP server.") } + log := logrus.New() log.Hooks.Add(hook) - log.Info("Today was a good day.") - var buf = make([]byte, 1500) - n, _, err := c.ReadFromUDP(buf) - - if err != nil { - t.Fatalf("Error reading data from local UDP server") - } - - if n <= 0 { - t.Errorf("Nothing written to local UDP server.") - } + udp.ShouldReceive(t, "foo", func() { + log.Info("foo") + }) }