Search in sources :

Example 41 with Context

use of io.fabric8.kubernetes.api.model.Context in project fabric8-maven-plugin by fabric8io.

the class DockerHealthCheckEnricherTest method testEnrichFromSingleImage.

@Test
public void testEnrichFromSingleImage() throws Exception {
    // Setup mock behaviour
    new Expectations() {

        {
            context.getImages();
            result = Arrays.asList(new ImageConfiguration.Builder().alias("myImage").buildConfig(new BuildImageConfiguration.Builder().healthCheck(new HealthCheckConfiguration.Builder().mode(HealthCheckMode.cmd).cmd("/bin/check").timeout("1s").interval("1h1s").retries(3).build()).build()).build(), new ImageConfiguration.Builder().alias("myImage2").buildConfig(new BuildImageConfiguration.Builder().healthCheck(new HealthCheckConfiguration.Builder().mode(HealthCheckMode.cmd).cmd("/xxx/check").timeout("3s").interval("3h1s").retries(9).build()).build()).build());
        }
    };
    KubernetesListBuilder builder = createDeployment("myImage");
    DockerHealthCheckEnricher enricher = new DockerHealthCheckEnricher(context);
    enricher.addMissingResources(builder);
    KubernetesList list = builder.build();
    assertEquals(1, list.getItems().size());
    assertHealthCheckMatching(builder.build().getItems().get(0), "livenessProbe", "/bin/check", 1, 3601, 3);
    assertHealthCheckMatching(builder.build().getItems().get(0), "readinessProbe", "/bin/check", 1, 3601, 3);
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.junit.Test)

Example 42 with Context

use of io.fabric8.kubernetes.api.model.Context in project fabric8-maven-plugin by fabric8io.

the class VertxHealthCheckEnricherTest method testDefaultConfiguration.

@Test
public void testDefaultConfiguration() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
    final Properties props = new Properties();
    new Expectations() {

        {
            context.getProject().getProperties();
            result = props;
        }
    };
    Probe probe = enricher.getLivenessProbe();
    assertNull(probe);
    probe = enricher.getReadinessProbe();
    assertNull(probe);
}
Also used : Expectations(mockit.Expectations) Properties(java.util.Properties) Probe(io.fabric8.kubernetes.api.model.Probe) Test(org.junit.Test)

Example 43 with Context

use of io.fabric8.kubernetes.api.model.Context in project fabric8-maven-plugin by fabric8io.

the class VertxHealthCheckEnricherTest method testCustomConfiguration.

@Test
public void testCustomConfiguration() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
    final Properties props = new Properties();
    props.put("vertx.health.path", "/health");
    props.put("vertx.health.port", " 8081 ");
    props.put("vertx.health.scheme", " https");
    new Expectations() {

        {
            context.getProject().getProperties();
            result = props;
        }
    };
    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertNull(probe.getHttpGet().getHost());
    assertEquals(probe.getHttpGet().getScheme(), "https");
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 8081);
    assertEquals(probe.getHttpGet().getPath(), "/health");
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getHttpGet().getScheme(), "https");
    assertNull(probe.getHttpGet().getHost());
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 8081);
    assertEquals(probe.getHttpGet().getPath(), "/health");
}
Also used : Expectations(mockit.Expectations) Properties(java.util.Properties) Probe(io.fabric8.kubernetes.api.model.Probe) Test(org.junit.Test)

Example 44 with Context

use of io.fabric8.kubernetes.api.model.Context in project fabric8-maven-plugin by fabric8io.

the class VertxHealthCheckEnricherTest method testLivenessDisabledAndReadinessEnabledUsingConfig.

@Test
public void testLivenessDisabledAndReadinessEnabledUsingConfig() {
    final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap("vertx-health-check", new TreeMap(ImmutableMap.of(VertxHealthCheckEnricher.Config.readiness.name(), "/ping", VertxHealthCheckEnricher.Config.path.name(), ""))));
    new Expectations() {

        {
            context.getConfig();
            result = config;
        }
    };
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
    Probe probe = enricher.getLivenessProbe();
    assertNull(probe);
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getHttpGet().getPath(), "/ping");
}
Also used : Expectations(mockit.Expectations) TreeMap(java.util.TreeMap) Probe(io.fabric8.kubernetes.api.model.Probe) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 45 with Context

use of io.fabric8.kubernetes.api.model.Context in project fabric8-maven-plugin by fabric8io.

the class VertxHealthCheckEnricherTest method testDifferentPathForLivenessAndReadiness.

@Test
public void testDifferentPathForLivenessAndReadiness() {
    VertxHealthCheckEnricher enricher = new VertxHealthCheckEnricher(context);
    final Properties props = new Properties();
    props.put("vertx.health.path", "/ping");
    props.put("vertx.health.readiness.path", "/ready");
    new Expectations() {

        {
            context.getProject().getProperties();
            result = props;
        }
    };
    Probe probe = enricher.getLivenessProbe();
    assertNotNull(probe);
    assertNull(probe.getHttpGet().getHost());
    assertEquals(probe.getHttpGet().getScheme(), "HTTP");
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 8080);
    assertEquals(probe.getHttpGet().getPath(), "/ping");
    probe = enricher.getReadinessProbe();
    assertNotNull(probe);
    assertEquals(probe.getHttpGet().getScheme(), "HTTP");
    assertNull(probe.getHttpGet().getHost());
    assertEquals(probe.getHttpGet().getPort().getIntVal().intValue(), 8080);
    assertEquals(probe.getHttpGet().getPath(), "/ready");
}
Also used : Expectations(mockit.Expectations) Properties(java.util.Properties) Probe(io.fabric8.kubernetes.api.model.Probe) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)135 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)58 Async (io.vertx.ext.unit.Async)52 Expectations (mockit.Expectations)34 Probe (io.fabric8.kubernetes.api.model.Probe)33 Reconciliation (io.strimzi.controller.cluster.Reconciliation)24 File (java.io.File)23 Git (org.eclipse.jgit.api.Git)23 GitContext (io.fabric8.api.GitContext)21 IOException (java.io.IOException)21 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)20 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 HashMap (java.util.HashMap)17 LockHandle (io.fabric8.api.LockHandle)15 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)15 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)15 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)15 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 Resource (io.fabric8.kubernetes.client.dsl.Resource)14