Search in sources :

Example 1 with NumberPort

use of me.snowdrop.istio.api.networking.v1alpha3.NumberPort in project kubernetes by ballerinax.

the class IstioVirtualServiceTest method useServiceAnnotationPortTest.

/**
 * Build bal file with istio virtual service annotations. Check if service annotation port is used.
 *
 * @throws IOException               Error when loading the generated yaml.
 * @throws InterruptedException      Error when compiling the ballerina file.
 * @throws KubernetesPluginException Error when deleting the generated artifacts folder.
 */
@Test(groups = { "istio" })
public void useServiceAnnotationPortTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "svc_port.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate virtual service yaml
    File vsFile = KUBERNETES_TARGET_PATH.resolve("svc_port_istio_virtual_service.yaml").toFile();
    Assert.assertTrue(vsFile.exists());
    VirtualService virtualService = KubernetesTestUtils.loadYaml(vsFile);
    Assert.assertNotNull(virtualService.getMetadata());
    Assert.assertEquals(virtualService.getMetadata().getName(), "helloep-istio-vs", "Invalid virtual service name");
    Assert.assertNotNull(virtualService.getSpec());
    Assert.assertEquals(virtualService.getSpec().getHosts().size(), 1);
    Assert.assertEquals(virtualService.getSpec().getHosts().get(0), "*", "Invalid host value.");
    Assert.assertEquals(virtualService.getSpec().getHttp().size(), 1, "Invalid number of http items");
    Assert.assertNotNull(virtualService.getSpec().getHttp().get(0).getRoute());
    Assert.assertEquals(virtualService.getSpec().getHttp().get(0).getRoute().size(), 1);
    Assert.assertEquals(virtualService.getSpec().getHttp().get(0).getRoute().get(0).getDestination().getHost(), "hello", "Invalid route destination host");
    Assert.assertTrue(virtualService.getSpec().getHttp().get(0).getRoute().get(0).getDestination().getPort().getPort() instanceof NumberPort);
    NumberPort numberPort = (NumberPort) virtualService.getSpec().getHttp().get(0).getRoute().get(0).getDestination().getPort().getPort();
    Assert.assertEquals(numberPort.getNumber().intValue(), 8080, "Invalid port found");
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : NumberPort(me.snowdrop.istio.api.networking.v1alpha3.NumberPort) VirtualService(me.snowdrop.istio.api.networking.v1alpha3.VirtualService) File(java.io.File) Test(org.testng.annotations.Test)

Example 2 with NumberPort

use of me.snowdrop.istio.api.networking.v1alpha3.NumberPort in project kubernetes by ballerinax.

the class Sample16Test method validateTravelAgencyVirtualService.

@Test
public void validateTravelAgencyVirtualService() {
    Assert.assertNotNull(virtualService);
    Assert.assertNotNull(virtualService.getMetadata());
    Assert.assertEquals(virtualService.getMetadata().getName(), "travelagencyep-istio-vs", "Invalid virtual service name");
    Assert.assertNotNull(virtualService.getSpec());
    Assert.assertNotNull(virtualService.getSpec().getGateways());
    Assert.assertEquals(virtualService.getSpec().getGateways().size(), 1);
    Assert.assertEquals(virtualService.getSpec().getGateways().get(0), "travelagencyep-istio-gw", "Invalid gateway");
    Assert.assertNotNull(virtualService.getSpec().getHosts());
    Assert.assertEquals(virtualService.getSpec().getHosts().size(), 1);
    Assert.assertEquals(virtualService.getSpec().getHosts().get(0), "*", "Invalid host value.");
    Assert.assertNotNull(virtualService.getSpec().getHttp());
    Assert.assertEquals(virtualService.getSpec().getHttp().size(), 1, "Invalid number of http items");
    Assert.assertNotNull(virtualService.getSpec().getHttp().get(0).getRoute());
    Assert.assertEquals(virtualService.getSpec().getHttp().get(0).getRoute().size(), 1);
    Assert.assertEquals(virtualService.getSpec().getHttp().get(0).getRoute().get(0).getDestination().getHost(), "travelagencyep-svc", "Invalid route destination host");
    PortSelector.Port destinationPort = virtualService.getSpec().getHttp().get(0).getRoute().get(0).getDestination().getPort().getPort();
    Assert.assertTrue(destinationPort instanceof NumberPort);
    NumberPort destinationPortNumber = (NumberPort) destinationPort;
    Assert.assertEquals(destinationPortNumber.getNumber().intValue(), 9090, "Invalid port");
    Assert.assertEquals(virtualService.getSpec().getHttp().get(0).getRoute().get(0).getWeight().intValue(), 100, "Invalid weight");
}
Also used : PortSelector(me.snowdrop.istio.api.networking.v1alpha3.PortSelector) NumberPort(me.snowdrop.istio.api.networking.v1alpha3.NumberPort) Test(org.testng.annotations.Test)

Example 3 with NumberPort

use of me.snowdrop.istio.api.networking.v1alpha3.NumberPort in project kubernetes by ballerinax.

the class IstioVirtualServiceTest method emptyAnnotationTest.

/**
 * Build bal file with istio virtual service annotations having no fields.
 *
 * @throws IOException               Error when loading the generated yaml.
 * @throws InterruptedException      Error when compiling the ballerina file.
 * @throws KubernetesPluginException Error when deleting the generated artifacts folder.
 */
@Test(groups = { "istio" })
public void emptyAnnotationTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "empty_annotation.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate virtual service yaml
    File vsFile = KUBERNETES_TARGET_PATH.resolve("empty_annotation_istio_virtual_service.yaml").toFile();
    Assert.assertTrue(vsFile.exists());
    VirtualService virtualService = KubernetesTestUtils.loadYaml(vsFile);
    Assert.assertNotNull(virtualService.getMetadata());
    Assert.assertEquals(virtualService.getMetadata().getName(), "helloep-istio-vs", "Invalid virtual service name");
    Assert.assertNotNull(virtualService.getSpec());
    Assert.assertEquals(virtualService.getSpec().getHosts().size(), 1);
    Assert.assertEquals(virtualService.getSpec().getHosts().get(0), "*", "Invalid host value.");
    Assert.assertEquals(virtualService.getSpec().getHttp().size(), 1, "Invalid number of http items");
    Assert.assertNotNull(virtualService.getSpec().getHttp().get(0).getRoute());
    Assert.assertEquals(virtualService.getSpec().getHttp().get(0).getRoute().size(), 1);
    Assert.assertEquals(virtualService.getSpec().getHttp().get(0).getRoute().get(0).getDestination().getHost(), "hello", "Invalid route destination host");
    Assert.assertTrue(virtualService.getSpec().getHttp().get(0).getRoute().get(0).getDestination().getPort().getPort() instanceof NumberPort);
    NumberPort numberPort = (NumberPort) virtualService.getSpec().getHttp().get(0).getRoute().get(0).getDestination().getPort().getPort();
    Assert.assertEquals(numberPort.getNumber().intValue(), 9090, "Invalid port found");
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : NumberPort(me.snowdrop.istio.api.networking.v1alpha3.NumberPort) VirtualService(me.snowdrop.istio.api.networking.v1alpha3.VirtualService) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

NumberPort (me.snowdrop.istio.api.networking.v1alpha3.NumberPort)3 Test (org.testng.annotations.Test)3 File (java.io.File)2 VirtualService (me.snowdrop.istio.api.networking.v1alpha3.VirtualService)2 PortSelector (me.snowdrop.istio.api.networking.v1alpha3.PortSelector)1