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
|
go-udp-testing
==============
[](https://travis-ci.org/stvp/go-udp-testing)
Provides UDP socket test helpers for Go.
[Documentation](http://godoc.org/github.com/stvp/go-udp-testing)
Examples
--------
```go
package main
import (
"github.com/stvp/go-udp-testing"
"testing"
)
func TestStatsdReporting(t *testing.T) {
udp.SetAddr(":8125")
udp.ShouldReceiveOnly(t, "mystat:2|g", func() {
statsd.Gauge("mystat", 2)
})
udp.ShouldNotReceiveOnly(t, "mystat:1|c", func() {
statsd.Gauge("bukkit", 2)
})
udp.ShouldReceive(t, "bar:2|g", func() {
statsd.Gauge("foo", 2)
statsd.Gauge("bar", 2)
statsd.Gauge("baz", 2)
})
udp.ShouldNotReceive(t, "bar:2|g", func() {
statsd.Gauge("foo", 2)
statsd.Gauge("baz", 2)
})
expected := []string{
"bar:2|g",
"baz:5|g",
}
udp.ShouldReceiveAll(t, expected, func() {
statsd.Gauge("bar", 2)
statsd.Gauge("baz", 2)
})
unexpected := []string{
"bar",
"baz",
}
udp.ShouldNotReceiveAny(t, unexpected, func() {
statsd.Gauge("foo", 1)
})
expected := []string{ "" }
"bar:2|g",
"baz:5|g",
}
unexpected := []string{
"foo",
}
udp.ShouldReceiveAllAndNotReceiveAny(t, expected, unexpected, func() {
statsd.Gauge("bar", 2)
statsd.Gauge("baz", 5)
})
}
```
|