-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
142 lines (117 loc) · 2.84 KB
/
main_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package main
import (
"strings"
"testing"
//"time"
)
func getPeerFromChannel(channel string) (peer string) {
if strings.Contains(channel, "IAX2/trunk_") {
return ""
}
//try to find the destination from channel
delim := '-'
if strings.Contains(channel, "@") {
delim = '@'
}
w := strings.FieldsFunc(channel, func(r rune) bool {
switch r {
case '/', delim:
return true
}
return false
})
if len(w) >= 3 {
return w[len(w)-2]
} else {
return channel
}
}
func Test_DstChannel(t *testing.T) {
var channel = "SIP/6006-01010101"
peer := getPeerFromChannel(channel)
if peer != "6006" {
t.Error("It is not good peer for channel [%s].", channel)
t.Fail()
}
channel = "DAHDI/g1/0493948400-01010101"
peer = getPeerFromChannel(channel)
if peer != "0493948400" {
t.Error("It is not good peer [%s] for channel [%s].", peer, channel)
t.Fail()
}
t.Log("dstChannelTester test passed.")
channel = "'DAHDI/132-1'"
peer = getPeerFromChannel(channel)
if peer != "132" {
t.Error("It is not good peer [%s] for channel [%s].", peer, channel)
t.Fail()
}
channel = "Local/8129@DLPN_DialPlan1-000000e6;1"
peer = getPeerFromChannel(channel)
if peer != "8129" {
t.Errorf("It is not good peer [%s] for channel [%s].", peer, channel)
t.Fail()
}
channel = "IAX2/trunk_2-13959"
peer = getPeerFromChannel(channel)
if peer != "" {
t.Errorf("It is not good peer [%s] for channel [%s].", peer, channel)
t.Fail()
}
t.Log("dstChannelTester test passed.")
}
/*func Test_EventWatcher_MySql(t *testing.T) {
loadConfig(false)
config := GetConfig()
eventWatcher := NewEventWatcher(config)
go eventWatcher.run()
ev := &Event{
Mask: new(BitSet),
Datas: "EV_MYSQL_ERROR data ev",
Name: "EV_MYSQL_ERROR name",
}
ev.Mask.Set(EV_MYSQL_ERROR)
eventWatcher.event <- ev
//
ev1 := &Event{
Mask: new(BitSet),
Datas: "EV_MYSQL_ERROR data ev1 ",
Name: "EV_MYSQL_ERROR name",
}
ev1.Mask.Set(EV_MYSQL_ERROR)
eventWatcher.event <- ev1
ev2 := &Event{
Mask: new(BitSet),
Datas: "EV_MYSQL_SUCCESS data ev2",
Name: "EV_MYSQL_SUCCESS name",
}
ev2.Mask.Set(EV_MYSQL_SUCCESS)
eventWatcher.event <- ev2
ev3 := &Event{
Mask: new(BitSet),
Datas: "EV_MYSQL_SUCCESS data ev3",
Name: "EV_MYSQL_SUCCESS name",
}
ev3.Mask.Set(EV_MYSQL_SUCCESS)
eventWatcher.event <- ev3
ev4 := &Event{
Mask: new(BitSet),
Datas: "EV_MYSQL_ERROR data ev4",
Name: "EV_MYSQL_ERROR name",
}
ev4.Mask.Set(EV_MYSQL_ERROR)
eventWatcher.event <- ev4
time.Sleep(1 * time.Second)
if eventWatcher.eventsMask.HasBit(EV_MYSQL_ERROR) || !eventWatcher.eventsMask.HasBit(EV_MYSQL_SUCCESS) {
t.Fail()
}
}*/
/*func Test_CallOriginator(t *testing.T) {
addr := "192.168.3.20"
port := 5038
user := "astmanager"
pswd := "lepanos"
callOriginator := NewCallOriginator(addr, port, user, pswd)
callOriginator.testCall <- true
time.Sleep(1 * time.Second)
}*/