use of io.kubernetes.client.openapi.JSON in project java by kubernetes-client.
the class DefaultSharedIndexInformerWireMockTest method testInformerReListingOnListForbidden.
@Test
public void testInformerReListingOnListForbidden() throws InterruptedException {
CoreV1Api coreV1Api = new CoreV1Api(client);
stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods")).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(403).withHeader("Content-Type", "application/json").withBody(new JSON().serialize(new V1Status().apiVersion("v1").kind("Status").code(403).reason("RBAC forbidden")))));
SharedInformerFactory factory = new SharedInformerFactory();
SharedIndexInformer<V1Pod> podInformer = factory.sharedIndexInformerFor((CallGeneratorParams params) -> {
try {
return coreV1Api.listNamespacedPodCall(namespace, null, null, null, null, null, null, params.resourceVersion, null, params.timeoutSeconds, params.watch, null);
} catch (ApiException e) {
throw new RuntimeException(e);
}
}, V1Pod.class, V1PodList.class);
factory.startAllRegisteredInformers();
// Sleep mroe than 1s so that informer can perform multiple rounds of list-watch
Thread.sleep(3000);
verify(moreThan(1), getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods")).withQueryParam("watch", equalTo("false")));
factory.stopAllRegisteredInformers();
}
Aggregations