/usr/share/gocode/src/github.com/stvp/go-udp-testing/udp_test.go is in golang-github-stvp-go-udp-testing-dev 0.0~git20150316.0.abcd331-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 74 75 76 77 78 79 80 | package udp
import (
"net"
"testing"
"time"
)
var (
testAddr = ":8126"
)
func TestAll(t *testing.T) {
udpClient, err := net.DialTimeout("udp", testAddr, time.Second)
if err != nil {
t.Fatal(err)
}
SetAddr(testAddr)
testValues := [][]interface{}{
[]interface{}{"foo", "foo", true, true},
[]interface{}{"foo", "bar", false, false},
[]interface{}{"foo", "foobar", false, true},
[]interface{}{"foo", "", false, false},
[]interface{}{"", "", true, true},
}
for _, values := range testValues {
shouldGet := values[0].(string)
sendString := values[1].(string)
shouldEquals := values[2].(bool)
shouldContains := values[3].(bool)
got, equals, contains := get(t, shouldGet, func() {
udpClient.Write([]byte(sendString))
})
if got != sendString {
t.Errorf("Should've got %#v but got %#v", sendString, got)
}
if equals != shouldEquals {
t.Errorf("Equals should've been %#v but was %#v", shouldEquals, equals)
}
if contains != shouldContains {
t.Errorf("Contains should've been %#v but was %#v", shouldContains, contains)
}
}
ShouldReceiveOnly(t, "foo", func() {
udpClient.Write([]byte("foo"))
})
ShouldNotReceiveOnly(t, "bar", func() {
udpClient.Write([]byte("foo"))
})
ShouldReceive(t, "foo", func() {
udpClient.Write([]byte("barfoo"))
})
ShouldNotReceive(t, "bar", func() {
udpClient.Write([]byte("fooba"))
})
ShouldReceiveAll(t, []string{"foo", "bar"}, func() {
udpClient.Write([]byte("foobizbar"))
})
ShouldNotReceiveAny(t, []string{"fooby", "bars"}, func() {
udpClient.Write([]byte("foobizbar"))
})
ShouldReceiveAllAndNotReceiveAny(t, []string{"foo", "bar"}, []string{"fooby", "bars"}, func() {
udpClient.Write([]byte("foobizbar"))
})
// This should fail, but it also shouldn't stall out
// ShouldReceive(t, "foo", func() {})
}
|