2222
2323import io .kubernetes .client .informer .cache .Cache ;
2424import io .kubernetes .client .informer .cache .Lister ;
25+ import io .kubernetes .client .openapi .ApiClient ;
2526import io .kubernetes .client .openapi .apis .CoreV1Api ;
2627import io .kubernetes .client .openapi .models .CoreV1EndpointPort ;
2728import io .kubernetes .client .openapi .models .CoreV1EndpointPortBuilder ;
3435import io .kubernetes .client .openapi .models .V1ServicePortBuilder ;
3536import io .kubernetes .client .openapi .models .V1ServiceSpecBuilder ;
3637import org .assertj .core .util .Strings ;
38+ import org .junit .jupiter .api .BeforeAll ;
3739import org .junit .jupiter .api .BeforeEach ;
3840import org .junit .jupiter .api .Test ;
3941import org .mockito .Mockito ;
5052 */
5153class KubernetesClientDiscoveryClientFilterMetadataTest {
5254
53- private static final CoreV1Api CORE_V1_API = Mockito .mock (CoreV1Api .class );
54-
55- private static final SharedInformerFactoryStub STUB = new SharedInformerFactoryStub ();
56-
5755 private static final SharedInformerStub <V1Service > SERVICE_SHARED_INFORMER_STUB = new SharedInformerStub <>();
5856
5957 private static final SharedInformerStub <V1Endpoints > ENDPOINTS_SHARED_INFORMER_STUB = new SharedInformerStub <>();
6058
59+ private static CoreV1Api coreV1Api ;
60+
61+ private static SharedInformerFactoryStub sharedInformerFactoryStub ;
62+
6163 private Cache <V1Service > servicesCache ;
6264
6365 private Lister <V1Service > servicesLister ;
@@ -66,6 +68,15 @@ class KubernetesClientDiscoveryClientFilterMetadataTest {
6668
6769 private Lister <V1Endpoints > endpointsLister ;
6870
71+ @ BeforeAll
72+ static void beforeAll () {
73+ coreV1Api = Mockito .mock (CoreV1Api .class );
74+ ApiClient apiClient = Mockito .mock (ApiClient .class );
75+ Mockito .when (coreV1Api .getApiClient ()).thenReturn (apiClient );
76+
77+ sharedInformerFactoryStub = new SharedInformerFactoryStub (apiClient );
78+ }
79+
6980 @ BeforeEach
7081 void beforeEach () {
7182 servicesCache = new Cache <>();
@@ -85,8 +96,9 @@ void testAllExtraMetadataDisabled() {
8596 false , null , Set .of (), Map .of (), null , metadata , 0 , true , false , null );
8697
8798 KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient (
88- List .of (STUB ), List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
89- List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API , x -> true );
99+ List .of (sharedInformerFactoryStub ), List .of (servicesLister ), List .of (endpointsLister ),
100+ List .of (SERVICE_SHARED_INFORMER_STUB ), List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , coreV1Api ,
101+ x -> true );
90102
91103 setup (serviceId , "ns" , Map .of ("l1" , "lab" ), Map .of ("l1" , "lab" ), Map .of (80 , "http" , 5555 , "" ));
92104
@@ -105,8 +117,9 @@ void testLabelsEnabled() {
105117 false , null , Set .of (), Map .of (), null , metadata , 0 , true , false , null );
106118
107119 KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient (
108- List .of (STUB ), List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
109- List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API , x -> true );
120+ List .of (sharedInformerFactoryStub ), List .of (servicesLister ), List .of (endpointsLister ),
121+ List .of (SERVICE_SHARED_INFORMER_STUB ), List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , coreV1Api ,
122+ x -> true );
110123
111124 setup (serviceId , "ns" , Map .of ("l1" , "v1" , "l2" , "v2" ), Map .of ("l1" , "lab" ), Map .of (80 , "http" , 5555 , "" ));
112125
@@ -126,8 +139,9 @@ void testLabelsEnabledWithPrefix() {
126139 false , null , Set .of (), Map .of (), null , metadata , 0 , true , false , null );
127140
128141 KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient (
129- List .of (STUB ), List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
130- List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API , x -> true );
142+ List .of (sharedInformerFactoryStub ), List .of (servicesLister ), List .of (endpointsLister ),
143+ List .of (SERVICE_SHARED_INFORMER_STUB ), List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , coreV1Api ,
144+ x -> true );
131145
132146 setup (serviceId , "ns" , Map .of ("l1" , "v1" , "l2" , "v2" ), Map .of ("l1" , "lab" ), Map .of (80 , "http" , 5555 , "" ));
133147
@@ -147,8 +161,9 @@ void testAnnotationsEnabled() {
147161 false , null , Set .of (), Map .of (), null , metadata , 0 , true , false , null );
148162
149163 KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient (
150- List .of (STUB ), List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
151- List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API , x -> true );
164+ List .of (sharedInformerFactoryStub ), List .of (servicesLister ), List .of (endpointsLister ),
165+ List .of (SERVICE_SHARED_INFORMER_STUB ), List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , coreV1Api ,
166+ x -> true );
152167
153168 setup (serviceId , "ns" , Map .of ("l1" , "v1" ), Map .of ("a1" , "v1" , "a2" , "v2" ), Map .of (80 , "http" , 5555 , "" ));
154169
@@ -168,8 +183,9 @@ void testAnnotationsEnabledWithPrefix() {
168183 false , null , Set .of (), Map .of (), null , metadata , 0 , true , false , null );
169184
170185 KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient (
171- List .of (STUB ), List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
172- List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API , x -> true );
186+ List .of (sharedInformerFactoryStub ), List .of (servicesLister ), List .of (endpointsLister ),
187+ List .of (SERVICE_SHARED_INFORMER_STUB ), List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , coreV1Api ,
188+ x -> true );
173189
174190 setup (serviceId , "ns" , Map .of ("l1" , "v1" ), Map .of ("a1" , "v1" , "a2" , "v2" ), Map .of (80 , "http" , 5555 , "" ));
175191
@@ -189,8 +205,9 @@ void testPortsEnabled() {
189205 false , null , Set .of (), Map .of (), null , metadata , 0 , true , false , null );
190206
191207 KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient (
192- List .of (STUB ), List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
193- List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API , x -> true );
208+ List .of (sharedInformerFactoryStub ), List .of (servicesLister ), List .of (endpointsLister ),
209+ List .of (SERVICE_SHARED_INFORMER_STUB ), List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , coreV1Api ,
210+ x -> true );
194211
195212 setup (serviceId , "test" , Map .of ("l1" , "v1" ), Map .of ("a1" , "v1" , "a2" , "v2" ), Map .of (80 , "http" , 5555 , "" ));
196213
@@ -210,8 +227,9 @@ void testPortsEnabledWithPrefix() {
210227 false , null , Set .of (), Map .of (), null , metadata , 0 , true , false , null );
211228
212229 KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient (
213- List .of (STUB ), List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
214- List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API , x -> true );
230+ List .of (sharedInformerFactoryStub ), List .of (servicesLister ), List .of (endpointsLister ),
231+ List .of (SERVICE_SHARED_INFORMER_STUB ), List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , coreV1Api ,
232+ x -> true );
215233
216234 setup (serviceId , "ns" , Map .of ("l1" , "v1" ), Map .of ("a1" , "v1" , "a2" , "v2" ), Map .of (80 , "http" , 5555 , "" ));
217235
@@ -231,8 +249,9 @@ void testLabelsAndAnnotationsAndPortsEnabledWithPrefix() {
231249 false , null , Set .of (), Map .of (), null , metadata , 0 , true , false , null );
232250
233251 KubernetesClientInformerDiscoveryClient discoveryClient = new KubernetesClientInformerDiscoveryClient (
234- List .of (STUB ), List .of (servicesLister ), List .of (endpointsLister ), List .of (SERVICE_SHARED_INFORMER_STUB ),
235- List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , CORE_V1_API , x -> true );
252+ List .of (sharedInformerFactoryStub ), List .of (servicesLister ), List .of (endpointsLister ),
253+ List .of (SERVICE_SHARED_INFORMER_STUB ), List .of (ENDPOINTS_SHARED_INFORMER_STUB ), properties , coreV1Api ,
254+ x -> true );
236255
237256 setup (serviceId , "ns" , Map .of ("l1" , "la1" ), Map .of ("a1" , "an1" , "a2" , "an2" ), Map .of (80 , "http" , 5555 , "" ));
238257
0 commit comments