4
4
"testing"
5
5
6
6
"github.com/stretchr/testify/assert"
7
- v1 "k8s.io/api/core /v1"
7
+ discoveryv1 "k8s.io/api/discovery /v1"
8
8
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
9
)
10
10
@@ -14,21 +14,19 @@ func TestAdd(t *testing.T) {
14
14
endpoints = change
15
15
})
16
16
h .OnAdd ("bad" , false )
17
- h .OnAdd (& v1.Endpoints {Subsets : []v1.EndpointSubset {
18
- {
19
- Addresses : []v1.EndpointAddress {
20
- {
21
- IP : "0.0.0.1" ,
22
- },
23
- {
24
- IP : "0.0.0.2" ,
25
- },
26
- {
27
- IP : "0.0.0.3" ,
28
- },
17
+ h .OnAdd (& discoveryv1.EndpointSlice {
18
+ Endpoints : []discoveryv1.Endpoint {
19
+ {
20
+ Addresses : []string {"0.0.0.1" },
21
+ },
22
+ {
23
+ Addresses : []string {"0.0.0.2" },
24
+ },
25
+ {
26
+ Addresses : []string {"0.0.0.3" },
29
27
},
30
28
},
31
- }} , false )
29
+ }, false )
32
30
assert .ElementsMatch (t , []string {"0.0.0.1" , "0.0.0.2" , "0.0.0.3" }, endpoints )
33
31
}
34
32
@@ -37,34 +35,30 @@ func TestDelete(t *testing.T) {
37
35
h := NewEventHandler (func (change []string ) {
38
36
endpoints = change
39
37
})
40
- h .OnAdd (& v1.Endpoints {Subsets : []v1.EndpointSubset {
41
- {
42
- Addresses : []v1.EndpointAddress {
43
- {
44
- IP : "0.0.0.1" ,
45
- },
46
- {
47
- IP : "0.0.0.2" ,
48
- },
49
- {
50
- IP : "0.0.0.3" ,
51
- },
38
+ h .OnAdd (& discoveryv1.EndpointSlice {
39
+ Endpoints : []discoveryv1.Endpoint {
40
+ {
41
+ Addresses : []string {"0.0.0.1" },
42
+ },
43
+ {
44
+ Addresses : []string {"0.0.0.2" },
45
+ },
46
+ {
47
+ Addresses : []string {"0.0.0.3" },
52
48
},
53
49
},
54
- }} , false )
50
+ }, false )
55
51
h .OnDelete ("bad" )
56
- h .OnDelete (& v1.Endpoints {Subsets : []v1.EndpointSubset {
57
- {
58
- Addresses : []v1.EndpointAddress {
59
- {
60
- IP : "0.0.0.1" ,
61
- },
62
- {
63
- IP : "0.0.0.2" ,
64
- },
52
+ h .OnDelete (& discoveryv1.EndpointSlice {
53
+ Endpoints : []discoveryv1.Endpoint {
54
+ {
55
+ Addresses : []string {"0.0.0.1" },
56
+ },
57
+ {
58
+ Addresses : []string {"0.0.0.2" },
65
59
},
66
60
},
67
- }} )
61
+ })
68
62
assert .ElementsMatch (t , []string {"0.0.0.3" }, endpoints )
69
63
}
70
64
@@ -73,36 +67,28 @@ func TestUpdate(t *testing.T) {
73
67
h := NewEventHandler (func (change []string ) {
74
68
endpoints = change
75
69
})
76
- h .OnUpdate (& v1.Endpoints {
77
- Subsets : []v1.EndpointSubset {
70
+ h .OnUpdate (& discoveryv1.EndpointSlice {
71
+ Endpoints : []discoveryv1.Endpoint {
72
+ {
73
+ Addresses : []string {"0.0.0.1" },
74
+ },
78
75
{
79
- Addresses : []v1.EndpointAddress {
80
- {
81
- IP : "0.0.0.1" ,
82
- },
83
- {
84
- IP : "0.0.0.2" ,
85
- },
86
- },
76
+ Addresses : []string {"0.0.0.2" },
87
77
},
88
78
},
89
79
ObjectMeta : metav1.ObjectMeta {
90
80
ResourceVersion : "1" ,
91
81
},
92
- }, & v1. Endpoints {
93
- Subsets : []v1. EndpointSubset {
82
+ }, & discoveryv1. EndpointSlice {
83
+ Endpoints : []discoveryv1. Endpoint {
94
84
{
95
- Addresses : []v1.EndpointAddress {
96
- {
97
- IP : "0.0.0.1" ,
98
- },
99
- {
100
- IP : "0.0.0.2" ,
101
- },
102
- {
103
- IP : "0.0.0.3" ,
104
- },
105
- },
85
+ Addresses : []string {"0.0.0.1" },
86
+ },
87
+ {
88
+ Addresses : []string {"0.0.0.2" },
89
+ },
90
+ {
91
+ Addresses : []string {"0.0.0.3" },
106
92
},
107
93
},
108
94
ObjectMeta : metav1.ObjectMeta {
@@ -116,33 +102,25 @@ func TestUpdateNoChange(t *testing.T) {
116
102
h := NewEventHandler (func (change []string ) {
117
103
assert .Fail (t , "should not called" )
118
104
})
119
- h .OnUpdate (& v1. Endpoints {
120
- Subsets : []v1. EndpointSubset {
105
+ h .OnUpdate (& discoveryv1. EndpointSlice {
106
+ Endpoints : []discoveryv1. Endpoint {
121
107
{
122
- Addresses : []v1.EndpointAddress {
123
- {
124
- IP : "0.0.0.1" ,
125
- },
126
- {
127
- IP : "0.0.0.2" ,
128
- },
129
- },
108
+ Addresses : []string {"0.0.0.1" },
109
+ },
110
+ {
111
+ Addresses : []string {"0.0.0.2" },
130
112
},
131
113
},
132
114
ObjectMeta : metav1.ObjectMeta {
133
115
ResourceVersion : "1" ,
134
116
},
135
- }, & v1.Endpoints {
136
- Subsets : []v1.EndpointSubset {
117
+ }, & discoveryv1.EndpointSlice {
118
+ Endpoints : []discoveryv1.Endpoint {
119
+ {
120
+ Addresses : []string {"0.0.0.1" },
121
+ },
137
122
{
138
- Addresses : []v1.EndpointAddress {
139
- {
140
- IP : "0.0.0.1" ,
141
- },
142
- {
143
- IP : "0.0.0.2" ,
144
- },
145
- },
123
+ Addresses : []string {"0.0.0.2" },
146
124
},
147
125
},
148
126
ObjectMeta : metav1.ObjectMeta {
@@ -156,45 +134,35 @@ func TestUpdateChangeWithDifferentVersion(t *testing.T) {
156
134
h := NewEventHandler (func (change []string ) {
157
135
endpoints = change
158
136
})
159
- h .OnAdd (& v1.Endpoints {Subsets : []v1.EndpointSubset {
160
- {
161
- Addresses : []v1.EndpointAddress {
162
- {
163
- IP : "0.0.0.1" ,
164
- },
165
- {
166
- IP : "0.0.0.3" ,
167
- },
137
+ h .OnAdd (& discoveryv1.EndpointSlice {
138
+ Endpoints : []discoveryv1.Endpoint {
139
+ {
140
+ Addresses : []string {"0.0.0.1" },
141
+ },
142
+ {
143
+ Addresses : []string {"0.0.0.3" },
168
144
},
169
145
},
170
- }}, false )
171
- h .OnUpdate (& v1.Endpoints {
172
- Subsets : []v1.EndpointSubset {
146
+ }, false )
147
+ h .OnUpdate (& discoveryv1.EndpointSlice {
148
+ Endpoints : []discoveryv1.Endpoint {
149
+ {
150
+ Addresses : []string {"0.0.0.1" },
151
+ },
173
152
{
174
- Addresses : []v1.EndpointAddress {
175
- {
176
- IP : "0.0.0.1" ,
177
- },
178
- {
179
- IP : "0.0.0.3" ,
180
- },
181
- },
153
+ Addresses : []string {"0.0.0.3" },
182
154
},
183
155
},
184
156
ObjectMeta : metav1.ObjectMeta {
185
157
ResourceVersion : "1" ,
186
158
},
187
- }, & v1.Endpoints {
188
- Subsets : []v1.EndpointSubset {
159
+ }, & discoveryv1.EndpointSlice {
160
+ Endpoints : []discoveryv1.Endpoint {
161
+ {
162
+ Addresses : []string {"0.0.0.1" },
163
+ },
189
164
{
190
- Addresses : []v1.EndpointAddress {
191
- {
192
- IP : "0.0.0.1" ,
193
- },
194
- {
195
- IP : "0.0.0.2" ,
196
- },
197
- },
165
+ Addresses : []string {"0.0.0.2" },
198
166
},
199
167
},
200
168
ObjectMeta : metav1.ObjectMeta {
@@ -209,63 +177,49 @@ func TestUpdateNoChangeWithDifferentVersion(t *testing.T) {
209
177
h := NewEventHandler (func (change []string ) {
210
178
endpoints = change
211
179
})
212
- h .OnAdd (& v1.Endpoints {Subsets : []v1.EndpointSubset {
213
- {
214
- Addresses : []v1.EndpointAddress {
215
- {
216
- IP : "0.0.0.1" ,
217
- },
218
- {
219
- IP : "0.0.0.2" ,
220
- },
180
+ h .OnAdd (& discoveryv1.EndpointSlice {
181
+ Endpoints : []discoveryv1.Endpoint {
182
+ {
183
+ Addresses : []string {"0.0.0.1" },
184
+ },
185
+ {
186
+ Addresses : []string {"0.0.0.2" },
221
187
},
222
188
},
223
- }}, false )
224
- h .OnUpdate ("bad" , & v1.Endpoints {Subsets : []v1.EndpointSubset {
225
- {
226
- Addresses : []v1.EndpointAddress {
227
- {
228
- IP : "0.0.0.1" ,
229
- },
189
+ }, false )
190
+ h .OnUpdate ("bad" , & discoveryv1.EndpointSlice {
191
+ Endpoints : []discoveryv1.Endpoint {
192
+ {
193
+ Addresses : []string {"0.0.0.1" },
230
194
},
231
195
},
232
- }})
233
- h .OnUpdate (& v1.Endpoints {Subsets : []v1.EndpointSubset {
234
- {
235
- Addresses : []v1.EndpointAddress {
236
- {
237
- IP : "0.0.0.1" ,
238
- },
196
+ })
197
+ h .OnUpdate (& discoveryv1.EndpointSlice {
198
+ Endpoints : []discoveryv1.Endpoint {
199
+ {
200
+ Addresses : []string {"0.0.0.1" },
239
201
},
240
202
},
241
- }}, "bad" )
242
- h .OnUpdate (& v1.Endpoints {
243
- Subsets : []v1.EndpointSubset {
203
+ }, "bad" )
204
+ h .OnUpdate (& discoveryv1.EndpointSlice {
205
+ Endpoints : []discoveryv1.Endpoint {
206
+ {
207
+ Addresses : []string {"0.0.0.1" },
208
+ },
244
209
{
245
- Addresses : []v1.EndpointAddress {
246
- {
247
- IP : "0.0.0.1" ,
248
- },
249
- {
250
- IP : "0.0.0.2" ,
251
- },
252
- },
210
+ Addresses : []string {"0.0.0.2" },
253
211
},
254
212
},
255
213
ObjectMeta : metav1.ObjectMeta {
256
214
ResourceVersion : "1" ,
257
215
},
258
- }, & v1.Endpoints {
259
- Subsets : []v1.EndpointSubset {
216
+ }, & discoveryv1.EndpointSlice {
217
+ Endpoints : []discoveryv1.Endpoint {
218
+ {
219
+ Addresses : []string {"0.0.0.1" },
220
+ },
260
221
{
261
- Addresses : []v1.EndpointAddress {
262
- {
263
- IP : "0.0.0.1" ,
264
- },
265
- {
266
- IP : "0.0.0.2" ,
267
- },
268
- },
222
+ Addresses : []string {"0.0.0.2" },
269
223
},
270
224
},
271
225
ObjectMeta : metav1.ObjectMeta {
0 commit comments