-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnextip_test.go
More file actions
67 lines (56 loc) · 1.61 KB
/
Copy pathnextip_test.go
File metadata and controls
67 lines (56 loc) · 1.61 KB
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
package nextip
import (
"errors"
"testing"
)
func TestNextIPsReturnsRequestedCount(t *testing.T) {
next, err := NextIPs("192.168.100.13/24", 3)
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
expected := []string{"192.168.100.14", "192.168.100.15", "192.168.100.16"}
if len(next) != len(expected) {
t.Fatalf("expected %d IPs, got %d", len(expected), len(next))
}
for i, ip := range next {
if ip.String() != expected[i] {
t.Fatalf("unexpected IP at index %d: got %s want %s", i, ip.String(), expected[i])
}
}
}
func TestNextIPsWithStepReturnsRequestedCount(t *testing.T) {
next, err := NextIPsWithStep("192.168.100.102/24", 3, 3)
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
expected := []string{"192.168.100.105", "192.168.100.108", "192.168.100.111"}
if len(next) != len(expected) {
t.Fatalf("expected %d IPs, got %d", len(expected), len(next))
}
for i, ip := range next {
if ip.String() != expected[i] {
t.Fatalf("unexpected IP at index %d: got %s want %s", i, ip.String(), expected[i])
}
}
}
func TestNextIPsReturnsErrorWhenOutOfSubnet(t *testing.T) {
_, err := NextIPs("192.168.100.255/24", 1)
if err == nil {
t.Fatal("expected an error")
}
if !errors.Is(err, ErrOutOfSubnet) {
t.Fatalf("expected ErrOutOfSubnet, got %v", err)
}
}
func TestNextIPsReturnsErrorForInvalidCount(t *testing.T) {
_, err := NextIPs("192.168.100.1/24", 0)
if err == nil {
t.Fatal("expected an error")
}
}
func TestNextIPsWithStepReturnsErrorForInvalidStep(t *testing.T) {
_, err := NextIPsWithStep("192.168.100.1/24", 1, 0)
if err == nil {
t.Fatal("expected an error")
}
}