forked from dropbox/llama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
udp_test.go
49 lines (45 loc) · 1.09 KB
/
udp_test.go
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
package llama
import (
"net"
"testing"
)
func TestUnpackUdpData(t *testing.T) {
// Test with good data first
// "abcdefghij"
signature := [10]byte{97, 98, 99, 100, 101, 102, 103, 104, 105, 106}
data := UdpData{
Signature: signature,
}
bytes, err := PackUdpData(&data)
HandleMinorError(err)
unpacked, err := UnpackUdpData(bytes)
if err != nil {
t.Error("Was unable to unpack data successfully")
}
// Compare the actual structs
if *unpacked != data {
t.Error("Data unpacked, but lost in translation")
}
// Now verify that bad data doesn't work
badData := []byte{1, 2, 3, 4, 5}
_, err = UnpackUdpData(badData)
if err == nil {
t.Error("No error returned for bad data")
}
}
func TestSetTos(t *testing.T) {
// Resolve a local addr
myAddr, _ := net.ResolveUDPAddr("udp", ":0")
// Create a connection
conn, _ := net.ListenUDP("udp", myAddr)
// Set the ToS value
tosVal := 240
newTos := byte(tosVal)
SetTos(conn, newTos)
// Verify the ToS value
val := GetTos(conn)
if val != newTos {
t.Error("New ToS value not set correctly. Set", tosVal, "and got",
val, "instead.")
}
}