-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathattribute_test.go
More file actions
39 lines (31 loc) · 979 Bytes
/
Copy pathattribute_test.go
File metadata and controls
39 lines (31 loc) · 979 Bytes
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
package stun
import (
"bytes"
"testing"
)
func TestNewAttribute(t *testing.T) {
mappedAddress := NewMappedAddress(IPv4, 19302, 134744072)
attribute := NewAttribute(1, mappedAddress)
if attributeType := attribute.Type; attributeType != 1 {
t.Errorf(`attribute.Type = %d, want 1`, attributeType)
}
if length := attribute.Length; length != 5 {
t.Errorf(`attribute.Length = %d, want 5`, length)
}
if value := attribute.Value; value != mappedAddress {
t.Errorf(`attribute.Value = %s, want %s`, value, mappedAddress.String())
}
}
func TestSerializeAttribute(t *testing.T) {
mappedAddress := NewMappedAddress(IPv4, 19302, 134744072)
attribute := NewAttribute(1, mappedAddress)
buffer := attribute.Serialize()
matchingBuffer := []byte{
0x00, 0x01, 0x00, 0x05, // Type, Length
0x01, 0x4B, 0x66, 0x08, // Value
0x08, 0x08, 0x08,
}
if !bytes.Equal(buffer, matchingBuffer) {
t.Errorf(`attribute.Serialize() = %v, want %v`, buffer, matchingBuffer)
}
}