1
16
17 package options
18
19 import (
20 "testing"
21 )
22
23 func TestGetServiceIPAndRanges(t *testing.T) {
24 tests := []struct {
25 body string
26 apiServerServiceIP string
27 primaryServiceIPRange string
28 secondaryServiceIPRange string
29 expectedError bool
30 }{
31 {"", "10.0.0.1", "10.0.0.0/24", "<nil>", false},
32 {"192.0.2.1/24", "192.0.2.1", "192.0.2.0/24", "<nil>", false},
33 {"192.0.2.1/24,192.168.128.0/17", "192.0.2.1", "192.0.2.0/24", "192.168.128.0/17", false},
34
35 {"192.0.2.1/24,2001:db2:1:3:4::1/112", "192.0.2.1", "192.0.2.0/24", "2001:db2:1:3:4::/112", false},
36
37 {"2001:db2:1:3:4::1/112,192.0.2.1/24", "2001:db2:1:3:4::1", "2001:db2:1:3:4::/112", "192.0.2.0/24", false},
38
39 {"192.0.2.1/30,192.168.128.0/17", "<nil>", "<nil>", "<nil>", true},
40
41 {"192.0.2.1/33,192.168.128.0/17", "<nil>", "<nil>", "<nil>", true},
42
43 {"192.0.2.1/24,192.168.128.0/33", "<nil>", "<nil>", "<nil>", true},
44
45 {"2001:db2:1:3:4::1/129,192.0.2.1/24", "<nil>", "<nil>", "<nil>", true},
46
47 {"192.0.2.1/24,2001:db2:1:3:4::1/129", "<nil>", "<nil>", "<nil>", true},
48
49 {"192.0.2.1,192.168.128.0/17", "<nil>", "<nil>", "<nil>", true},
50
51 {"192.0.2.1/24,192.168.128.1", "<nil>", "<nil>", "<nil>", true},
52
53 {"2001:db2:1:3:4::1,192.0.2.1/24", "<nil>", "<nil>", "<nil>", true},
54
55 {"192.0.2.1/24,2001:db2:1:3:4::1", "<nil>", "<nil>", "<nil>", true},
56
57 {"bad.ip.range,192.168.0.2/24", "<nil>", "<nil>", "<nil>", true},
58
59 {"192.168.0.2/24,bad.ip.range", "<nil>", "<nil>", "<nil>", true},
60 }
61
62 for _, test := range tests {
63 apiServerServiceIP, primaryServiceIPRange, secondaryServiceIPRange, err := getServiceIPAndRanges(test.body)
64
65 if apiServerServiceIP.String() != test.apiServerServiceIP {
66 t.Errorf("expected apiServerServiceIP: %s, got: %s", test.apiServerServiceIP, apiServerServiceIP.String())
67 }
68
69 if primaryServiceIPRange.String() != test.primaryServiceIPRange {
70 t.Errorf("expected primaryServiceIPRange: %s, got: %s", test.primaryServiceIPRange, primaryServiceIPRange.String())
71 }
72
73 if secondaryServiceIPRange.String() != test.secondaryServiceIPRange {
74 t.Errorf("expected secondaryServiceIPRange: %s, got: %s", test.secondaryServiceIPRange, secondaryServiceIPRange.String())
75 }
76
77 if (err == nil) == test.expectedError {
78 t.Errorf("expected err to be: %t, but it was %t", test.expectedError, !test.expectedError)
79 }
80 }
81 }
82
View as plain text