-
Notifications
You must be signed in to change notification settings - Fork 46
/
ami_test.go
102 lines (96 loc) · 2.41 KB
/
ami_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
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
package amigo
import (
"bufio"
"bytes"
"io"
"strconv"
"testing"
)
var messagePairs = []struct {
message string
expected map[string]string
err error
}{
{
`Event: EndpointList
ObjectType: endpoint
ObjectName: XXXXX
Transport: transport-udp
Aor: XXX
Auths:
OutboundAuths : looong untrimed value
Contacts: XXXX/sip:XXXX
DeviceState: Unavailable
ActiveChannels:
`,
map[string]string{
"Event": "EndpointList",
"ObjectType": "endpoint",
"ObjectName": "XXXXX",
"Transport": "transport-udp",
"Aor": "XXX",
"Auth": "",
"OutboundAuths": "looong untrimed value",
"Contacts": "XXXX/sip:XXXX",
"DeviceState": "Unavailable",
"ActiveChannels": "",
},
nil,
},
{
`Response: Follows
Privilege: Command
No such command 'core show hi' (type 'core show help core show hi' for other possible commands)
`,
map[string]string{
"Response": "Follows",
"Privilege": "Command",
"CommandResponse": "No such command 'core show hi' (type 'core show help core show hi' for other possible commands)",
},
nil,
},
{
`Response: Follows
Privilege: Command
No such command 'core show hi' (type 'core show help core show hi' for other possible commands)
--END COMMAND--
`,
map[string]string{
"Response": "Follows",
"Privilege": "Command",
"CommandResponse": "No such command 'core show hi' (type 'core show help core show hi' for other possible commands)",
},
nil,
},
{
`Response: Follows
Privilege: Command
No such command 'core show hi'
(type 'core show help core show hi' for other possible commands)
--END COMMAND--
`,
map[string]string{
"Response": "Follows",
"Privilege": "Command",
"CommandResponse": "No such command 'core show hi'\n(type 'core show help core show hi' for other possible commands)",
},
io.EOF,
},
}
func TestReadMessage(t *testing.T) {
for i, pair := range messagePairs {
t.Run("pair "+strconv.Itoa(i), func(t *testing.T) {
buf := bytes.NewBuffer([]byte(pair.message))
reader := bufio.NewReader(buf)
message, err := readMessage(reader)
if err != pair.err {
t.Fatalf("readMessage error mismatched. Expected '%v', got '%v'", pair.err, err)
}
for k, v := range message {
if pair.expected[k] != v {
t.Fatalf("readMessage error. Key '%s', Expected value '%s', got '%s'", k, pair.expected[k], v)
}
}
})
}
}