-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
killswitch_test.go
50 lines (42 loc) · 1.18 KB
/
killswitch_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
package killswitch_test
import (
"testing"
"github.com/vpn-kill-switch/killswitch"
)
const succeeded = "\u2713"
const failed = "\u2717"
func TestKillSwitch(t *testing.T) {
tt := []struct {
peerIp string
expectedIp string
}{
{
peerIp: "127.0.0.1",
expectedIp: "127.0.0.1",
},
{
peerIp: "1.2.3.4",
expectedIp: "1.2.3.4",
},
{
peerIp: "",
expectedIp: "0.0.0.0",
},
}
for i, tst := range tt {
t.Logf("\tTest %d: \t%s", i, tst.peerIp)
network, _ := killswitch.New(tst.peerIp)
if network.PeerIP != tst.expectedIp {
t.Fatalf("\t%s\t Should have correct peer IP: exp[%s] got[%s] ", failed, tst.peerIp, network.PeerIP)
}
t.Logf("\t%s\t Should have correct peer IP", succeeded)
if len(network.P2PInterfaces) != 0 {
t.Fatalf("\t%s\t Should have correct P2PInterfaces length: exp[%d] got[%d] ", failed, 0, len(network.P2PInterfaces))
}
t.Logf("\t%s\t Should have correct P2PInterfaces ", succeeded)
if len(network.UpInterfaces) != 0 {
t.Fatalf("\t%s\t Should have correct UpInterfaces length: exp[%d] got[%d] ", failed, 0, len(network.UpInterfaces))
}
t.Logf("\t%s\t Should have correct UpInterfaces ", succeeded)
}
}