-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitbucketipvalidator_test.go
61 lines (57 loc) · 1.36 KB
/
bitbucketipvalidator_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
package utils
import (
"net"
"testing"
log "github.com/sirupsen/logrus"
)
type checkdatabiv struct {
ipAddr string
expectedResult bool
}
func TestValidateIP(t *testing.T) {
checkdatas := []checkdatabiv{
{
ipAddr: "10.10.10.10",
expectedResult: false,
}, {
ipAddr: "20.20.20.20",
expectedResult: false,
}, { // "cidr": "18.234.32.128/25"
ipAddr: "18.234.32.3",
expectedResult: false,
}, {
ipAddr: "18.234.32.127",
expectedResult: false,
}, {
ipAddr: "18.234.32.128",
expectedResult: true,
}, {
ipAddr: "18.234.32.136",
expectedResult: true,
}, {
ipAddr: "18.234.32.136",
expectedResult: true,
}, { // "cidr": "34.218.168.212/32"
ipAddr: "34.218.168.211",
expectedResult: false,
}, {
ipAddr: "34.218.168.212",
expectedResult: true,
}, {
ipAddr: "34.218.168.213",
expectedResult: false,
},
}
logger := log.New()
biv, err := NewBitbucketIPValidator(logger)
if err != nil {
t.Fatalf("Error creating a new BitbucketIpValidator: %v", err)
}
for _, checkdata := range checkdatas {
ip := net.ParseIP(checkdata.ipAddr)
valid := biv.ValidateIP(ip)
if valid != checkdata.expectedResult {
t.Fatalf("For IP %v the expected validation result is %v, but it was %v", ip, checkdata.expectedResult, valid)
}
}
}