Search in sources :

Example 1 with EqualToPattern

use of com.github.tomakehurst.wiremock.matching.EqualToPattern in project java by kubernetes-client.

the class KubectlRolloutTest method testKubectlRolloutHistoryDeploymentWithRevisionShouldWork.

@Test
public void testKubectlRolloutHistoryDeploymentWithRevisionShouldWork() throws KubectlException, IOException {
    wireMockRule.stubFor(get(urlPathEqualTo("/apis/apps/v1/namespaces/default/deployments/foo")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(DEPLOYMENT))))));
    wireMockRule.stubFor(get(urlPathEqualTo("/apis/apps/v1/namespaces/default/replicasets")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(REPLICASET_LIST))))));
    V1PodTemplateSpec template = Kubectl.rollout(V1Deployment.class).history().apiClient(apiClient).name("foo").namespace("default").revision(3).skipDiscovery().execute();
    wireMockRule.verify(1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/deployments/foo"))));
    wireMockRule.verify(1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/replicasets"))).withQueryParam("labelSelector", new EqualToPattern("app = bar")));
    Assert.assertNotNull(template);
}
Also used : V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) Test(org.junit.Test)

Example 2 with EqualToPattern

use of com.github.tomakehurst.wiremock.matching.EqualToPattern in project java by kubernetes-client.

the class KubectlRolloutTest method testKubectlRolloutHistoryDaemonSetWithRevisionShouldWork.

@Test
public void testKubectlRolloutHistoryDaemonSetWithRevisionShouldWork() throws KubectlException, IOException {
    wireMockRule.stubFor(get(urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(DAEMON_SET))))));
    wireMockRule.stubFor(get(urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(DAEMON_SET_CONTROLLER_REVISION_LIST))))));
    wireMockRule.stubFor(patch(urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(PATCHED_DAEMON_SET))))));
    V1PodTemplateSpec template = Kubectl.rollout(V1DaemonSet.class).history().apiClient(apiClient).name("foo").namespace("default").revision(2).skipDiscovery().execute();
    wireMockRule.verify(1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo"))));
    wireMockRule.verify(1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions"))).withQueryParam("labelSelector", new EqualToPattern("app = bar")));
    wireMockRule.verify(1, patchRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/daemonsets/foo"))).withQueryParam("dryRun", new EqualToPattern("All")));
    Assert.assertNotNull(template);
}
Also used : V1DaemonSet(io.kubernetes.client.openapi.models.V1DaemonSet) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) Test(org.junit.Test)

Example 3 with EqualToPattern

use of com.github.tomakehurst.wiremock.matching.EqualToPattern in project java by kubernetes-client.

the class DeploymentHelperTest method testGetAllReplicaSetsShouldWork.

@Test
public void testGetAllReplicaSetsShouldWork() throws IOException, ApiException {
    wireMockRule.stubFor(get(urlPathEqualTo("/apis/apps/v1/namespaces/default/replicasets")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(REPLICASET_LIST))))));
    AppsV1Api api = new AppsV1Api(this.apiClient);
    V1Deployment deployment = new JSON().deserialize(new String(Files.readAllBytes(Paths.get(DEPLOYMENT))), V1Deployment.class);
    List<V1ReplicaSet> oldRSes = new ArrayList<>();
    List<V1ReplicaSet> allOldRSes = new ArrayList<>();
    V1ReplicaSet newRs = DeploymentHelper.getAllReplicaSets(deployment, api, oldRSes, allOldRSes);
    wireMockRule.verify(1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/replicasets"))).withQueryParam("labelSelector", new EqualToPattern("app = bar")));
    Assert.assertNotNull(newRs);
    Assert.assertEquals(1, oldRSes.size());
    Assert.assertEquals(2, allOldRSes.size());
}
Also used : V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) ArrayList(java.util.ArrayList) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) JSON(io.kubernetes.client.openapi.JSON) V1ReplicaSet(io.kubernetes.client.openapi.models.V1ReplicaSet) Test(org.junit.Test)

Example 4 with EqualToPattern

use of com.github.tomakehurst.wiremock.matching.EqualToPattern in project ligoj-api by ligoj.

the class CurlProcessorTest method testHeadersOverrideDefault.

@Test
public void testHeadersOverrideDefault() {
    httpServer.stubFor(get(urlPathEqualTo("/")).withHeader("ACCEPT-charset", new EqualToPattern("utf-8")).willReturn(aResponse().withStatus(HttpStatus.SC_OK).withBody("CONTENT")));
    httpServer.start();
    final CurlProcessor processor = new CurlProcessor();
    Assertions.assertEquals("CONTENT", processor.get("http://localhost:" + MOCK_PORT, "ACCEPT-charset:utf-8"));
}
Also used : EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) Test(org.junit.jupiter.api.Test) AbstractServerTest(org.ligoj.app.AbstractServerTest)

Example 5 with EqualToPattern

use of com.github.tomakehurst.wiremock.matching.EqualToPattern in project java by kubernetes-client.

the class KubectlApplyTest method testApplyConfigMap.

@Test
public void testApplyConfigMap() throws KubectlException, IOException {
    wireMockRule.stubFor(patch(urlPathEqualTo("/api/v1/namespaces/foo/configmaps/bar")).withHeader("Content-Type", new EqualToPattern(V1Patch.PATCH_FORMAT_APPLY_YAML)).willReturn(aResponse().withStatus(200).withBody("{\"metadata\":{\"name\":\"bar\",\"namespace\":\"foo\"}}")));
    wireMockRule.stubFor(get(urlPathEqualTo("/api")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(DISCOVERY_API))))));
    wireMockRule.stubFor(get(urlPathEqualTo("/apis")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(DISCOVERY_APIS))))));
    wireMockRule.stubFor(get(urlPathEqualTo("/api/v1")).willReturn(aResponse().withStatus(200).withBody(new String(Files.readAllBytes(Paths.get(DISCOVERY_APIV1))))));
    V1ConfigMap configMap = Kubectl.apply(V1ConfigMap.class).apiClient(apiClient).resource(new V1ConfigMap().apiVersion("v1").metadata(new V1ObjectMeta().namespace("foo").name("bar")).data(new HashMap<String, String>() {

        {
            put("key1", "value1");
        }
    })).execute();
    wireMockRule.verify(1, patchRequestedFor(urlPathEqualTo("/api/v1/namespaces/foo/configmaps/bar")));
    assertNotNull(configMap);
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Test(org.junit.Test)

Aggregations

EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)7 Test (org.junit.Test)6 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)3 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)2 V1Deployment (io.kubernetes.client.openapi.models.V1Deployment)2 V1Patch (io.kubernetes.client.custom.V1Patch)1 JSON (io.kubernetes.client.openapi.JSON)1 AppsV1Api (io.kubernetes.client.openapi.apis.AppsV1Api)1 V1DaemonSet (io.kubernetes.client.openapi.models.V1DaemonSet)1 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)1 V1ReplicaSet (io.kubernetes.client.openapi.models.V1ReplicaSet)1 V1StatefulSet (io.kubernetes.client.openapi.models.V1StatefulSet)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 AbstractServerTest (org.ligoj.app.AbstractServerTest)1