forked from tehnerd/gnl2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gnl2go_test.go
71 lines (67 loc) · 1.56 KB
/
gnl2go_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package gnl2go
import (
"fmt"
"syscall"
"testing"
)
func TestAttrListSerDes(t *testing.T) {
al := CreateAttrListType(CtrlAttrList)
testMap := make(map[string]SerDes)
familyId := U16Type(1)
familyName := NulStringType("testFamily")
version := U32Type(1)
hdrSize := U32Type(100)
maxAttr := U32Type(14)
testMap["FAMILY_ID"] = &familyId
testMap["FAMILY_NAME"] = &familyName
testMap["VERSION"] = &version
testMap["HDRSIZE"] = &hdrSize
testMap["MAXATTR"] = &maxAttr
al.Set(testMap)
serializedList, err := al.Serialize()
if err != nil {
t.Errorf("cant serialize attr list, error: %v\n", err)
}
fmt.Println(serializedList)
err = al.Deserialize(serializedList)
if err != nil {
t.Errorf("cant deserialize attrl list. error: %v\n", err)
}
for k, v := range testMap {
if data, exist := al.Amap[k]; !exist {
t.Errorf("deserialized map not equal to original\n key %v doesnt exist\n", k)
} else {
data.Val()
v.Val()
}
}
var sd SerDes
sd = &al
sd.Val()
}
func TestToFromAFUnion(t *testing.T) {
fmt.Println("starting to test to/from af union")
v4addr := "1.4.2.1"
v6addr := "2a02:1::1"
if !validateIp(v4addr) || !validateIp(v6addr) {
t.Errorf("validation failed!\n")
return
}
af, addr, _ := toAFUnion(v4addr)
if af != syscall.AF_INET {
t.Errorf("to af failed")
return
}
v4dec, _ := fromAFUnion(af, addr)
fmt.Println(v4dec)
af, addr, _ = toAFUnion(v6addr)
if af != syscall.AF_INET6 {
t.Errorf("to af failed")
return
}
v6dec, err := fromAFUnion(af, addr)
if err != nil {
t.Errorf("cant decode ipv6 address\n")
}
fmt.Println(v6dec)
}