-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipv4addresstools_test.go
87 lines (69 loc) · 2.05 KB
/
ipv4addresstools_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
package nsojsonrpcrequestergo
import (
"errors"
"testing"
)
func TestIpV4Address(t *testing.T) {
scenarios := []struct {
input string
expect string
rcvError error
}{
{input: "192.168.1.1", expect: "192.168.1.1", rcvError: nil},
{input: "192.168.1.0501", expect: "192.168.1.0501", rcvError: errors.New("not a valid IPv4 address")},
}
for _, scenario := range scenarios {
value, err := IpV4Address(scenario.input)
if value != scenario.expect {
t.Errorf("expected %v got %v", scenario.expect, value)
}
if err != scenario.rcvError {
if err.Error() != scenario.rcvError.Error() {
t.Errorf("expected error %v got %v", scenario.rcvError, err)
}
}
}
}
func TestIpV4UnicastAddress(t *testing.T) {
scenarios := []struct {
input string
expect string
rcvError error
}{
{input: "192.168.1.1", expect: "192.168.1.1", rcvError: nil},
{input: "192.168.1.0501", expect: "192.168.1.0501", rcvError: errors.New("not a valid IPv4 address")},
{input: "224.0.0.1", expect: "224.0.0.1", rcvError: errors.New("not a valid IPv4 unicast address")},
}
for _, scenario := range scenarios {
value, err := IpV4UnicastAddress(scenario.input)
if value != scenario.expect {
t.Errorf("expected %v got %v", scenario.expect, value)
}
if err != scenario.rcvError {
if err.Error() != scenario.rcvError.Error() {
t.Errorf("expected error %v got %v", scenario.rcvError, err)
}
}
}
}
func TestIpV4MulticastAddress(t *testing.T) {
scenarios := []struct {
input string
expect string
rcvError error
}{
{input: "224.0.0.1", expect: "224.0.0.1", rcvError: nil},
{input: "192.168.1.1", expect: "192.168.1.1", rcvError: errors.New("not a valid IPv4 multicast address")},
}
for _, scenario := range scenarios {
value, err := IpV4MulticastAddress(scenario.input)
if value != scenario.expect {
t.Errorf("expected %v got %v", scenario.expect, value)
}
if err != scenario.rcvError {
if err.Error() != scenario.rcvError.Error() {
t.Errorf("expected error %v got %v", scenario.rcvError, err)
}
}
}
}