-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmanagement_test.go
135 lines (119 loc) · 3.96 KB
/
management_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
package openvpn
import (
"strconv"
"sync"
"testing"
)
var waitGroup sync.WaitGroup
func init() {
//logger, err := log.LoggerFromConfigAsFile("logconfig.xml")
//if err != nil {
//testConfig := `
//<seelog type="sync">
//<outputs formatid="main">
//<filter levels="trace">
//<console formatid="colored-trace"/>
//</filter>
//<filter levels="debug">
//<console formatid="colored-debug"/>
//</filter>
//<filter levels="info">
//<console formatid="colored-info"/>
//</filter>
//<filter levels="warn">
//<console formatid="colored-warn"/>
//</filter>
//<filter levels="error">
//<console formatid="colored-error"/>
//</filter>
//<filter levels="critical">
//<console formatid="colored-critical"/>
//</filter>
//</outputs>
//<formats>
//<format id="colored-trace" format="%Time %EscM(40)%Level%EscM(49) - %File:%Line - %Msg%n%EscM(0)"/>
//<format id="colored-debug" format="%Time %EscM(45)%Level%EscM(49) - %File:%Line - %Msg%n%EscM(0)"/>
//<format id="colored-info" format="%Time %EscM(46)%Level%EscM(49) - %File:%Line - %Msg%n%EscM(0)"/>
//<format id="colored-warn" format="%Time %EscM(43)%Level%EscM(49) - %File:%Line - %Msg%n%EscM(0)"/>
//<format id="colored-error" format="%Time %EscM(41)%Level%EscM(49) - %File:%Line - %Msg%n%EscM(0)"/>
//<format id="colored-critical" format="%Time %EscM(41)%Level%EscM(49) - %File:%Line - %Msg%n%EscM(0)"/>
//</formats>
//</seelog>`
//logger, _ = log.LoggerFromConfigAsBytes([]byte(testConfig))
//}
//log.ReplaceLogger(logger)
}
func TestNewManagement(t *testing.T) {
m := NewManagement(&Process{})
if m == nil {
t.Error("Return is nil")
}
}
func TestParse(t *testing.T) {
m := &Management{
events: make(chan []string),
buffer: make([]byte, 0),
}
done := make(chan bool)
go func() {
waitGroup.Add(1)
defer waitGroup.Done()
select {
case result := <-m.events:
for index := range result {
t.Log("Result[", index, "]: \n", strconv.Quote(result[index]))
}
if len(result) != 6 {
t.Error("Wrong length on answer, should be 5, is ", len(result))
}
if result[0] != "client-list" {
t.Error("result[0] is invalid")
}
if result[1] != "OpenVPN CLIENT LIST\n"+
"Updated, Thu Feb 13 23:39:20 2014\n"+
"Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since\n"+
"VPN_client,10.13.156.4:1194,12563,14885,Thu Feb 13 23:39:20 2014\n"+
"ROUTING TABLE\n"+
"Virtual Address,Common Name,Real Address,Last Ref\n"+
"192.168.11.4,VPN_client,10.13.156.4:1194,Thu Feb 13 23:39:20 2014\n"+
"GLOBAL STATS\n"+
"Max bcast/mcast queue length,0\n"+
"END\n" {
t.Error("result[1] is invalid")
}
if result[2] != " Thu Feb 13 23:39:20 2014" {
t.Error("result[2] is invalid")
}
if result[3] !=
"Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since\n"+
"VPN_client,10.13.156.4:1194,12563,14885,Thu Feb 13 23:39:20 2014" {
t.Error("result[3] is invalid")
}
if result[4] !=
"Virtual Address,Common Name,Real Address,Last Ref\n"+
"192.168.11.4,VPN_client,10.13.156.4:1194,Thu Feb 13 23:39:20 2014" {
t.Error("result[4] is invalid")
}
if result[5] != "Max bcast/mcast queue length,0" {
t.Error("result[5] is invalid")
}
return
case <-done:
t.Error("Parse done without result")
}
}()
m.parse([]byte("OpenVPN CLIENT LIST"), false)
m.parse([]byte("Updated, Thu Feb 13 23:39:20 2014"), false)
m.parse([]byte("Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since"), false)
m.parse([]byte("VPN_client,10.13.156.4:1194,12563,14885,Thu Feb 13 23:39:20 2014"), false)
m.parse([]byte(""), false)
m.parse([]byte("ROUTING TABLE"), false)
m.parse([]byte("Virtual Address,Common Name,Real Address,Last Ref"), false)
m.parse([]byte("192.168.11.4,VPN_client,10.13.156.4:1194,Thu Feb 13 23:39:20 2014"), false)
m.parse([]byte(""), false)
m.parse([]byte("GLOBAL STATS"), false)
m.parse([]byte("Max bcast/mcast queue length,0"), false)
m.parse([]byte("END"), false)
close(done)
waitGroup.Wait()
}