Search in sources :

Example 6 with VirtualService

use of me.snowdrop.istio.api.networking.v1alpha3.VirtualService 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

VirtualService (me.snowdrop.istio.api.networking.v1alpha3.VirtualService)5 Test (org.testng.annotations.Test)5 File (java.io.File)4 NumberPort (me.snowdrop.istio.api.networking.v1alpha3.NumberPort)3 IOException (java.io.IOException)1 PortSelector (me.snowdrop.istio.api.networking.v1alpha3.PortSelector)1 VirtualServiceBuilder (me.snowdrop.istio.api.networking.v1alpha3.VirtualServiceBuilder)1 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)1