-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathipgen_test.go
More file actions
110 lines (90 loc) · 1.95 KB
/
Copy pathipgen_test.go
File metadata and controls
110 lines (90 loc) · 1.95 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"testing"
)
func TestExpandCIDRFast(t *testing.T) {
blocks := []string{"192.168.1.0/24"}
ips := ExpandCIDR(blocks, "fast")
var result []string
for ip := range ips {
result = append(result, ip)
}
if len(result) != 3 {
t.Errorf("Fast mode: expected 3 IPs, got %d: %v", len(result), result)
}
expected := map[string]bool{
"192.168.1.1": false,
"192.168.1.53": false,
"192.168.1.254": false,
}
for _, ip := range result {
expected[ip] = true
}
for ip, found := range expected {
if !found {
t.Errorf("Fast mode: missing expected IP %s, got %v", ip, result)
}
}
}
func TestExpandCIDRMedium(t *testing.T) {
blocks := []string{"192.168.1.0/24"}
ips := ExpandCIDR(blocks, "medium")
var count int
for range ips {
count++
}
if count != 7 {
t.Errorf("Medium mode: expected 7 IPs, got %d", count)
}
}
func TestExpandCIDRAll(t *testing.T) {
blocks := []string{"192.168.1.0/24"}
ips := ExpandCIDR(blocks, "all")
var count int
for range ips {
count++
}
if count != 254 {
t.Errorf("All mode: expected 254 IPs, got %d", count)
}
}
func TestExpandCIDR16(t *testing.T) {
blocks := []string{"10.0.0.0/16"}
ips := ExpandCIDR(blocks, "fast")
var count int
for range ips {
count++
}
expected := 3 * 256
if count != expected {
t.Errorf("/16 fast mode: expected %d IPs, got %d", expected, count)
}
}
func TestCountCIDRIPs(t *testing.T) {
blocks := []string{"192.168.1.0/24"}
tests := []struct {
mode string
expected int
}{
{"fast", 3},
{"medium", 7},
{"all", 254},
}
for _, tt := range tests {
count := CountCIDRIPs(blocks, tt.mode)
if count != tt.expected {
t.Errorf("CountCIDRIPs(%s): expected %d, got %d", tt.mode, tt.expected, count)
}
}
}
func TestInvalidCIDR(t *testing.T) {
blocks := []string{"invalid-cidr"}
ips := ExpandCIDR(blocks, "fast")
var count int
for range ips {
count++
}
if count != 0 {
t.Errorf("Invalid CIDR: expected 0 IPs, got %d", count)
}
}