-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathmsg_test.go
More file actions
110 lines (106 loc) · 2.57 KB
/
Copy pathmsg_test.go
File metadata and controls
110 lines (106 loc) · 2.57 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package goStrongswanVici
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"testing"
)
func TestMsg(ot *testing.T) {
for _, msg := range []map[string]interface{}{
map[string]interface{}{
"a": "1",
},
map[string]interface{}{
"a": []string{
"1", "2",
},
},
map[string]interface{}{
"a": map[string]interface{}{
"d": "e",
"e": []string{
"1", "2",
},
},
},
map[string]interface{}{
"a": []string{
"1", "2",
},
"b": "a",
"c": map[string]interface{}{
"d": "e",
"e": []string{
"1", "2",
},
},
},
map[string]interface{}{
"key1": "value1",
"section1": map[string]interface{}{
"sub-section": map[string]interface{}{
"key2": "value2",
},
"list1": []string{"item1", "item2"},
},
},
} {
buf := &bytes.Buffer{}
in := segment{
typ: stCMD_REQUEST,
name: "good",
msg: msg,
}
err := writeSegment(buf, in)
mustNotError(err)
content := buf.Bytes()
out, err := readSegment(buf)
mustNotError(err)
//fmt.Println(content)
if !reflect.DeepEqual(in, out) {
in1, err := json.Marshal(in.msg)
mustNotError(err)
out1, err := json.Marshal(out.msg)
mustNotError(err)
fmt.Println(content)
panic("!reflect.DeepEqual(in,out)\n" + string(in1) + "\n" + string(out1))
}
}
content := []byte{
0x0, 0x0, 0x0, 0x5e, //length 94
0x1, //CMD_RESPONSE
0x3, //KEY_VALUE
0x6, 0x64, 0x61, 0x65, 0x6d, 0x6f, 0x6e, //daemon
0x0, 0x6, 0x63, 0x68, 0x61, 0x72, 0x6f, 0x6e, //charon
0x3, 0x7, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x0, 0x5, 0x35, 0x2e, 0x32, 0x2e, 0x32,
0x3, 0x7, 0x73, 0x79, 0x73, 0x6e, 0x61, 0x6d, 0x65, 0x0, 0x5, 0x4c, 0x69, 0x6e, 0x75, 0x78, 0x3, 0x7, 0x72,
0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x0, 0x11, 0x33, 0x2e, 0x31, 0x33, 0x2e, 0x30, 0x2d, 0x34, 0x34, 0x2d,
0x67, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x3, 0x7, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x0, 0x6, 0x78,
0x38, 0x36, 0x5f, 0x36, 0x34}
buf := bytes.NewBuffer(content)
out, err := readSegment(buf)
mustNotError(err)
in := segment{
typ: stCMD_RESPONSE,
msg: map[string]interface{}{
"daemon": "charon",
"machine": "x86_64",
"release": "3.13.0-44-generic",
"sysname": "Linux",
"version": "5.2.2",
},
}
if !reflect.DeepEqual(in, out) {
in1, err := json.Marshal(in.msg)
mustNotError(err)
out1, err := json.Marshal(out.msg)
mustNotError(err)
panic("!reflect.DeepEqual(in,out)\n" + string(in1) + "\n" + string(out1))
}
}
func mustNotError(err error) {
if err != nil {
panic(err)
}
}