forked from nklizhe/ovpnutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
107 lines (83 loc) · 1.75 KB
/
integration_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
// +build integration
package ovpnutil
import (
"fmt"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestKillOVPN(t *testing.T) {
// TODO: start an openvpn process
ctl, err := Dial("127.0.0.1:1337")
assert.NoError(t, err)
assert.NotNil(t, ctl)
defer ctl.Close()
err2 := ctl.Signal(SIGTERM)
assert.NoError(t, err2)
}
func TestGetpid(t *testing.T) {
ctl, err := Dial("127.0.0.1:1337")
assert.NoError(t, err)
assert.NotNil(t, ctl)
defer ctl.Close()
pid, err := ctl.Getpid()
assert.NoError(t, err)
assert.True(t, pid > 0)
}
func TestGetLogs(t *testing.T) {
ctl, err := Dial("127.0.0.1:1337")
assert.NoError(t, err)
assert.NotNil(t, ctl)
defer ctl.Close()
logs, err := ctl.GetLogs()
assert.NoError(t, err)
assert.NotEmpty(t, logs)
fmt.Println(logs)
}
func TestGetStates(t *testing.T) {
ctl, err := Dial("127.0.0.1:1337")
assert.NoError(t, err)
assert.NotNil(t, ctl)
defer ctl.Close()
states, err := ctl.GetStates()
assert.NoError(t, err)
assert.NotEmpty(t, states)
fmt.Println(states)
}
func TestSubscribeByteCount(t *testing.T) {
ctl, err := Dial("127.0.0.1:1337")
assert.NoError(t, err)
assert.NotNil(t, ctl)
defer ctl.Close()
cntIn := 0
chIn := make(chan int64)
cntOut := 0
chOut := make(chan int64)
// wait 5 seconds
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
err2 := ctl.SubscribeByteCount(chIn, chOut)
assert.NoError(t, err2)
timeout := time.After(time.Duration(3000) * time.Millisecond)
for {
select {
case in := <-chIn:
cntIn++
fmt.Printf("in: %d\n", in)
break
case out := <-chOut:
cntOut++
fmt.Printf("out: %d\n", out)
break
case <-timeout:
wg.Done()
break
}
}
}()
wg.Wait()
assert.True(t, cntIn > 0)
assert.True(t, cntOut > 0)
}