mirror of https://github.com/sirupsen/logrus.git
Use third-party UDP testing library to tighten up test.
This commit is contained in:
parent
e949967022
commit
51770fb4eb
|
@ -1,43 +1,26 @@
|
||||||
package logrus_papertrail
|
package logrus_papertrail
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/stvp/go-udp-testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWritingToUDP(t *testing.T) {
|
func TestWritingToUDP(t *testing.T) {
|
||||||
log := logrus.New()
|
|
||||||
port := 16661
|
port := 16661
|
||||||
|
udp.SetAddr(fmt.Sprintf(":%d", port))
|
||||||
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()
|
|
||||||
|
|
||||||
hook, err := NewPapertrailHook("localhost", port, "test")
|
hook, err := NewPapertrailHook("localhost", port, "test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unable to connect to local UDP server.")
|
t.Errorf("Unable to connect to local UDP server.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log := logrus.New()
|
||||||
log.Hooks.Add(hook)
|
log.Hooks.Add(hook)
|
||||||
log.Info("Today was a good day.")
|
|
||||||
|
|
||||||
var buf = make([]byte, 1500)
|
udp.ShouldReceive(t, "foo", func() {
|
||||||
n, _, err := c.ReadFromUDP(buf)
|
log.Info("foo")
|
||||||
|
})
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Error reading data from local UDP server")
|
|
||||||
}
|
|
||||||
|
|
||||||
if n <= 0 {
|
|
||||||
t.Errorf("Nothing written to local UDP server.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue