@@ -13,71 +13,63 @@ func TestFouDeserializeMsg(t *testing.T) {
1313
1414 // deserialize a valid message
1515 msg = []byte {3 , 1 , 0 , 0 , 5 , 0 , 2 , 0 , 2 , 0 , 0 , 0 , 6 , 0 , 1 , 0 , 21 , 179 , 0 , 0 , 5 , 0 , 3 , 0 , 4 , 0 , 0 , 0 , 5 , 0 , 4 , 0 , 1 , 0 , 0 , 0 }
16- if fou , err := deserializeFouMsg (msg ); err != nil {
17- t .Error (err .Error ())
18- } else {
19-
20- // check if message was deserialized correctly
21- if fou .Family != FAMILY_V4 {
22- t .Errorf ("expected family %d, got %d" , FAMILY_V4 , fou .Family )
23- }
16+ fou := deserializeFouMsg (msg )
17+ // check if message was deserialized correctly
18+ if fou .Family != FAMILY_V4 {
19+ t .Errorf ("expected family %d, got %d" , FAMILY_V4 , fou .Family )
20+ }
2421
25- if fou .Port != 5555 {
26- t .Errorf ("expected port 5555, got %d" , fou .Port )
27- }
22+ if fou .Port != 5555 {
23+ t .Errorf ("expected port 5555, got %d" , fou .Port )
24+ }
2825
29- if fou .Protocol != 4 { // ipip
30- t .Errorf ("expected protocol 4, got %d" , fou .Protocol )
31- }
26+ if fou .Protocol != 4 { // ipip
27+ t .Errorf ("expected protocol 4, got %d" , fou .Protocol )
28+ }
3229
33- if fou .EncapType != FOU_ENCAP_DIRECT {
34- t .Errorf ("expected encap type %d, got %d" , FOU_ENCAP_DIRECT , fou .EncapType )
35- }
30+ if fou .EncapType != FOU_ENCAP_DIRECT {
31+ t .Errorf ("expected encap type %d, got %d" , FOU_ENCAP_DIRECT , fou .EncapType )
3632 }
3733
3834 // deserialize a valid message(kernel >= 5.2)
3935 msg = []byte {3 , 1 , 0 , 0 , 5 , 0 , 2 , 0 , 2 , 0 , 0 , 0 , 6 , 0 , 1 , 0 , 43 , 103 , 0 , 0 , 6 , 0 , 10 , 0 , 86 , 206 , 0 , 0 , 5 , 0 , 3 , 0 , 0 , 0 , 0 , 0 , 5 , 0 , 4 , 0 , 2 , 0 , 0 , 0 , 8 , 0 , 11 , 0 , 0 , 0 , 0 , 0 , 8 , 0 , 6 , 0 , 1 , 2 , 3 , 4 , 8 , 0 , 8 , 0 , 5 , 6 , 7 , 8 }
40- if fou , err := deserializeFouMsg (msg ); err != nil {
41- t .Error (err .Error ())
42- } else {
43- if fou .Family != FAMILY_V4 {
44- t .Errorf ("expected family %d, got %d" , FAMILY_V4 , fou .Family )
45- }
36+ fou = deserializeFouMsg (msg )
37+ if fou .Family != FAMILY_V4 {
38+ t .Errorf ("expected family %d, got %d" , FAMILY_V4 , fou .Family )
39+ }
4640
47- if fou .Port != 11111 {
48- t .Errorf ("expected port 5555, got %d" , fou .Port )
49- }
41+ if fou .Port != 11111 {
42+ t .Errorf ("expected port 5555, got %d" , fou .Port )
43+ }
5044
51- if fou .Protocol != 0 { // gue
52- t .Errorf ("expected protocol 0, got %d" , fou .Protocol )
53- }
45+ if fou .Protocol != 0 { // gue
46+ t .Errorf ("expected protocol 0, got %d" , fou .Protocol )
47+ }
5448
55- if fou .IfIndex != 0 {
56- t .Errorf ("expected ifindex 0, got %d" , fou .Protocol )
57- }
49+ if fou .IfIndex != 0 {
50+ t .Errorf ("expected ifindex 0, got %d" , fou .Protocol )
51+ }
5852
59- if fou .EncapType != FOU_ENCAP_GUE {
60- t .Errorf ("expected encap type %d, got %d" , FOU_ENCAP_GUE , fou .EncapType )
61- }
53+ if fou .EncapType != FOU_ENCAP_GUE {
54+ t .Errorf ("expected encap type %d, got %d" , FOU_ENCAP_GUE , fou .EncapType )
55+ }
6256
63- if expected := net .IPv4 (1 , 2 , 3 , 4 ); ! fou .Local .Equal (expected ) {
64- t .Errorf ("expected local %v, got %v" , expected , fou .Local )
65- }
57+ if expected := net .IPv4 (1 , 2 , 3 , 4 ); ! fou .Local .Equal (expected ) {
58+ t .Errorf ("expected local %v, got %v" , expected , fou .Local )
59+ }
6660
67- if expected := net .IPv4 (5 , 6 , 7 , 8 ); ! fou .Peer .Equal (expected ) {
68- t .Errorf ("expected peer %v, got %v" , expected , fou .Peer )
69- }
61+ if expected := net .IPv4 (5 , 6 , 7 , 8 ); ! fou .Peer .Equal (expected ) {
62+ t .Errorf ("expected peer %v, got %v" , expected , fou .Peer )
63+ }
7064
71- if fou .PeerPort != 22222 {
72- t .Errorf ("expected peer port 0, got %d" , fou .PeerPort )
73- }
65+ if fou .PeerPort != 22222 {
66+ t .Errorf ("expected peer port 0, got %d" , fou .PeerPort )
7467 }
7568
7669 // unknown attribute should be skipped
7770 msg = []byte {3 , 1 , 0 , 0 , 5 , 0 , 112 , 0 , 2 , 0 , 0 , 0 , 5 , 0 , 2 , 0 , 2 , 0 , 0 }
78- if fou , err := deserializeFouMsg (msg ); err != nil {
79- t .Errorf ("unexpected error: %s" , err .Error ())
80- } else if fou .Family != 2 {
71+ fou = deserializeFouMsg (msg )
72+ if fou .Family != 2 {
8173 t .Errorf ("expected family 2, got %d" , fou .Family )
8274 }
8375}
0 commit comments