22
22
23
23
import io .kubernetes .client .informer .cache .Cache ;
24
24
import io .kubernetes .client .informer .cache .Lister ;
25
+ import io .kubernetes .client .openapi .apis .CoreV1Api ;
25
26
import io .kubernetes .client .openapi .models .CoreV1EndpointPort ;
26
27
import io .kubernetes .client .openapi .models .CoreV1EndpointPortBuilder ;
27
28
import io .kubernetes .client .openapi .models .V1Endpoints ;
36
37
import org .junit .jupiter .api .BeforeEach ;
37
38
import org .junit .jupiter .api .Test ;
38
39
40
+ import org .mockito .Mockito ;
39
41
import org .springframework .cloud .client .ServiceInstance ;
40
42
import org .springframework .cloud .kubernetes .commons .discovery .KubernetesDiscoveryProperties ;
43
+ import org .testcontainers .shaded .org .checkerframework .checker .units .qual .C ;
41
44
42
45
import static java .util .Map .entry ;
43
46
import static java .util .stream .Collectors .toList ;
@@ -62,6 +65,8 @@ class KubernetesDiscoveryClientFilterMetadataTest {
62
65
63
66
private Lister <V1Endpoints > endpointsLister ;
64
67
68
+ private static final CoreV1Api CORE_V1_API = Mockito .mock (CoreV1Api .class );
69
+
65
70
@ BeforeEach
66
71
void beforeEach () {
67
72
servicesCache = new Cache <>();
@@ -80,8 +85,9 @@ void testAllExtraMetadataDisabled() {
80
85
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties (true , false , Set .of (), true , 60 ,
81
86
false , null , Set .of (), Map .of (), null , metadata , 0 , true );
82
87
83
- KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (STUB , servicesLister ,
84
- endpointsLister , SERVICE_SHARED_INFORMER_STUB , ENDPOINTS_SHARED_INFORMER_STUB , properties );
88
+ KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (List .of (STUB ),
89
+ List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
90
+ List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API );
85
91
86
92
setup (serviceId , "ns" , Map .of ("l1" , "lab" ), Map .of ("l1" , "lab" ), Map .of (80 , "http" , 5555 , "" ));
87
93
@@ -99,8 +105,9 @@ void testLabelsEnabled() {
99
105
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties (true , false , Set .of (), true , 60 ,
100
106
false , null , Set .of (), Map .of (), null , metadata , 0 , true );
101
107
102
- KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (STUB , servicesLister ,
103
- endpointsLister , SERVICE_SHARED_INFORMER_STUB , ENDPOINTS_SHARED_INFORMER_STUB , properties );
108
+ KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (List .of (STUB ),
109
+ List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
110
+ List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API );
104
111
105
112
setup (serviceId , "ns" , Map .of ("l1" , "v1" , "l2" , "v2" ), Map .of ("l1" , "lab" ), Map .of (80 , "http" , 5555 , "" ));
106
113
@@ -119,8 +126,9 @@ void testLabelsEnabledWithPrefix() {
119
126
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties (true , false , Set .of (), true , 60 ,
120
127
false , null , Set .of (), Map .of (), null , metadata , 0 , true );
121
128
122
- KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (STUB , servicesLister ,
123
- endpointsLister , SERVICE_SHARED_INFORMER_STUB , ENDPOINTS_SHARED_INFORMER_STUB , properties );
129
+ KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (List .of (STUB ),
130
+ List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
131
+ List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API );
124
132
125
133
setup (serviceId , "ns" , Map .of ("l1" , "v1" , "l2" , "v2" ), Map .of ("l1" , "lab" ), Map .of (80 , "http" , 5555 , "" ));
126
134
@@ -139,8 +147,9 @@ void testAnnotationsEnabled() {
139
147
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties (true , false , Set .of (), true , 60 ,
140
148
false , null , Set .of (), Map .of (), null , metadata , 0 , true );
141
149
142
- KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (STUB , servicesLister ,
143
- endpointsLister , SERVICE_SHARED_INFORMER_STUB , ENDPOINTS_SHARED_INFORMER_STUB , properties );
150
+ KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (List .of (STUB ),
151
+ List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
152
+ List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API );
144
153
145
154
setup (serviceId , "ns" , Map .of ("l1" , "v1" ), Map .of ("a1" , "v1" , "a2" , "v2" ), Map .of (80 , "http" , 5555 , "" ));
146
155
@@ -159,8 +168,9 @@ void testAnnotationsEnabledWithPrefix() {
159
168
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties (true , false , Set .of (), true , 60 ,
160
169
false , null , Set .of (), Map .of (), null , metadata , 0 , true );
161
170
162
- KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (STUB , servicesLister ,
163
- endpointsLister , SERVICE_SHARED_INFORMER_STUB , ENDPOINTS_SHARED_INFORMER_STUB , properties );
171
+ KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (List .of (STUB ),
172
+ List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
173
+ List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API );
164
174
165
175
setup (serviceId , "ns" , Map .of ("l1" , "v1" ), Map .of ("a1" , "v1" , "a2" , "v2" ), Map .of (80 , "http" , 5555 , "" ));
166
176
@@ -179,8 +189,9 @@ void testPortsEnabled() {
179
189
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties (true , false , Set .of (), true , 60 ,
180
190
false , null , Set .of (), Map .of (), null , metadata , 0 , true );
181
191
182
- KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (STUB , servicesLister ,
183
- endpointsLister , SERVICE_SHARED_INFORMER_STUB , ENDPOINTS_SHARED_INFORMER_STUB , properties );
192
+ KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (List .of (STUB ),
193
+ List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
194
+ List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API );
184
195
185
196
setup (serviceId , "test" , Map .of ("l1" , "v1" ), Map .of ("a1" , "v1" , "a2" , "v2" ), Map .of (80 , "http" , 5555 , "" ));
186
197
@@ -199,8 +210,9 @@ void testPortsEnabledWithPrefix() {
199
210
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties (true , false , Set .of (), true , 60 ,
200
211
false , null , Set .of (), Map .of (), null , metadata , 0 , true );
201
212
202
- KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (STUB , servicesLister ,
203
- endpointsLister , SERVICE_SHARED_INFORMER_STUB , ENDPOINTS_SHARED_INFORMER_STUB , properties );
213
+ KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (List .of (STUB ),
214
+ List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
215
+ List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API );
204
216
205
217
setup (serviceId , "ns" , Map .of ("l1" , "v1" ), Map .of ("a1" , "v1" , "a2" , "v2" ), Map .of (80 , "http" , 5555 , "" ));
206
218
@@ -219,8 +231,9 @@ void testLabelsAndAnnotationsAndPortsEnabledWithPrefix() {
219
231
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties (true , false , Set .of (), true , 60 ,
220
232
false , null , Set .of (), Map .of (), null , metadata , 0 , true );
221
233
222
- KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (STUB , servicesLister ,
223
- endpointsLister , SERVICE_SHARED_INFORMER_STUB , ENDPOINTS_SHARED_INFORMER_STUB , properties );
234
+ KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient (List .of (STUB ),
235
+ List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
236
+ List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API );
224
237
225
238
setup (serviceId , "ns" , Map .of ("l1" , "la1" ), Map .of ("a1" , "an1" , "a2" , "an2" ), Map .of (80 , "http" , 5555 , "" ));
226
239
0 commit comments