-
Notifications
You must be signed in to change notification settings - Fork 0
/
args_test.go
96 lines (75 loc) · 1.84 KB
/
args_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
package main
import "testing"
func TestValidRegion(t *testing.T) {
if !validRegion("sfo3") {
t.Errorf("Expected a valid region")
}
if !validRegion("sfo") {
t.Errorf("Expected a valid region")
}
if validRegion("notdatacentercode") {
t.Errorf("Expected an invalid region")
}
if validRegion("before\nsfo3") {
t.Errorf("Expected an invalid region")
}
if validRegion("sf") {
t.Errorf("Expected an invalid region")
}
if validRegion("sf3") {
t.Errorf("Expected an invalid region")
}
}
func TestValidServerIP(t *testing.T) {
if !validServerIP("10.0.8.1") {
t.Errorf("Expected a valid server IP")
}
if validServerIP("10.0.8.256") {
t.Errorf("Expected an invalid server IP")
}
if validServerIP("8.8.8.8") {
t.Errorf("Expected an public IP to be considered invalid")
}
if validServerIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334") {
t.Errorf("Expected an invalid server IP")
}
if validServerIP("texthere") {
t.Errorf("Expected an invalid server IP")
}
if validServerIP("0") {
t.Errorf("Expected an invalid server IP")
}
}
func TestValidDNS(t *testing.T) {
if !validDNS("8.8.8.8") {
t.Errorf("Expected a valid DNS address")
}
if validDNS("2001:0db8:85a3:0000:0000:8a2e:0370:7334") {
t.Errorf("Expected an invalid DNS address")
}
if validDNS("texthere") {
t.Errorf("Expected an invalid DNS address")
}
if validDNS("0") {
t.Errorf("Expected an invalid DNS address")
}
}
func TestClientIP(t *testing.T) {
if clientIP("10.0.8.1") != "10.0.8.2" {
t.Errorf("Expected client IP to be next address of server")
}
}
func TestValidPort(t *testing.T) {
if !validPort(3000) {
t.Errorf("Expected a valid port")
}
if validPort(0) {
t.Errorf("Expected an invalid DNS address")
}
if validPort(-1) {
t.Errorf("Expected an invalid DNS address")
}
if validPort(65536) {
t.Errorf("Expected an invalid DNS address")
}
}