Search in sources :

Example 76 with Result

use of io.fabric8.insight.metrics.model.Result in project fabric8-maven-plugin by fabric8io.

the class EnvVarHandlerTest method envVarHandlerTest.

@Test
public void envVarHandlerTest() {
    // Some Environment Variable in Config
    EnvVar var1 = new EnvVarBuilder().withName("TEST1").withValue("OK").build();
    EnvVar var2 = new EnvVarBuilder().withName("TEST2").withValue("DONE").build();
    EnvVar var3 = new EnvVarBuilder().withName("TEST3").withValue("").build();
    env.clear();
    env.put(var1.getName(), var1.getValue());
    env.put(var2.getName(), var2.getValue());
    env.put(var3.getName(), var3.getValue());
    EnvVarHandler envVarHandler = new EnvVarHandler(project);
    new Expectations() {

        {
            externalEnvVarHandler.getExportedEnvironmentVariables(project, env);
            ret.putAll(env);
            result = ret;
        }
    };
    List<EnvVar> envVars = envVarHandler.getEnvironmentVariables(env);
    assertNotNull(envVars);
    assertEquals(4, envVars.size());
    assertTrue(envVars.contains(var1));
    assertTrue(envVars.contains(var2));
    assertTrue(envVars.contains(var3));
    assertTrue(envVars.contains(var4));
}
Also used : Expectations(mockit.Expectations) ExternalEnvVarHandler(io.fabric8.maven.core.extenvvar.ExternalEnvVarHandler) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) Test(org.junit.Test)

Example 77 with Result

use of io.fabric8.insight.metrics.model.Result in project fabric8-maven-plugin by fabric8io.

the class DockerRegistrySecretEnricherTest method testDockerRegistry.

@Test
public void testDockerRegistry() {
    new Expectations() {

        {
            {
                context.getSettings();
                result = createSettings();
            }
        }
    };
    DockerRegistrySecretEnricher enricher = new DockerRegistrySecretEnricher(context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    builder.addToSecretItems(createBaseSecret(true));
    enricher.addMissingResources(builder);
    KubernetesListBuilder expectedBuilder = new KubernetesListBuilder();
    Secret expectedSecret = createBaseSecret(false);
    expectedSecret.getData().put(SecretConstants.DOCKER_DATA_KEY, "eyJkb2NrZXIuaW8iOnsicGFzc3dvcmQiOiJwYXNzd29yZCIsImVtYWlsIjoiZm9vQGZvby5jb20iLCJ1c2VybmFtZSI6InVzZXJuYW1lIn19");
    expectedBuilder.addToSecretItems(expectedSecret);
    assertEquals(expectedBuilder.build(), builder.build());
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Secret(io.fabric8.kubernetes.api.model.Secret) Test(org.junit.Test)

Example 78 with Result

use of io.fabric8.insight.metrics.model.Result in project fabric8-maven-plugin by fabric8io.

the class BaseGeneratorTest method addLatestTagIfSnapshot.

@Test
public void addLatestTagIfSnapshot() {
    new Expectations() {

        {
            ctx.getProject();
            result = project;
            project.getVersion();
            result = "1.2-SNAPSHOT";
        }
    };
    BuildImageConfiguration.Builder builder = new BuildImageConfiguration.Builder();
    BaseGenerator generator = createGenerator(null);
    generator.addLatestTagIfSnapshot(builder);
    ;
    BuildImageConfiguration config = builder.build();
    List<String> tags = config.getTags();
    assertEquals(1, tags.size());
    assertTrue(tags.get(0).endsWith("latest"));
}
Also used : Expectations(mockit.Expectations) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 79 with Result

use of io.fabric8.insight.metrics.model.Result in project fabric8-maven-plugin by fabric8io.

the class EnricherManagerTest method enrichSimple.

@Test
public void enrichSimple() {
    new Expectations() {

        {
            context.getConfig();
            result = new ProcessorConfig(Arrays.asList("fmp-project"), null, new HashMap<String, TreeMap>());
        }
    };
    EnricherManager manager = new EnricherManager(null, context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    builder.addNewReplicaSetItem().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withName("test").withImage("busybox").endContainer().endSpec().endTemplate().endSpec().endReplicaSetItem();
    manager.enrich(builder);
    KubernetesList list = builder.build();
    assertEquals(1, list.getItems().size());
    ReplicaSet pod = (ReplicaSet) list.getItems().get(0);
    ObjectMeta metadata = pod.getMetadata();
    assertNotNull(metadata);
    Map<String, String> labels = metadata.getLabels();
    assertNotNull(labels);
    assertEquals("fabric8", labels.get("provider"));
}
Also used : Expectations(mockit.Expectations) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 80 with Result

use of io.fabric8.insight.metrics.model.Result in project fabric8-maven-plugin by fabric8io.

the class EnricherManagerTest method createDefaultResources.

@Test
public void createDefaultResources() {
    new Expectations() {

        {
            context.getConfig();
            result = new ProcessorConfig(Arrays.asList("fmp-controller"), null, null);
            context.getImages();
            result = new ImageConfiguration.Builder().alias("img1").name("img1").build();
        }
    };
    EnricherManager manager = new EnricherManager(null, context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    manager.createDefaultResources(builder);
    assertTrue(builder.build().getItems().size() > 0);
}
Also used : Expectations(mockit.Expectations) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)104 Expectations (mockit.Expectations)49 HashMap (java.util.HashMap)32 Map (java.util.Map)24 ArrayList (java.util.ArrayList)23 File (java.io.File)21 GitContext (io.fabric8.api.GitContext)20 IOException (java.io.IOException)20 Exchange (org.apache.camel.Exchange)20 Processor (org.apache.camel.Processor)20 DefaultPullPushPolicy (io.fabric8.git.internal.DefaultPullPushPolicy)18 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)17 Probe (io.fabric8.kubernetes.api.model.Probe)16 PatchResult (io.fabric8.patch.management.PatchResult)13 Properties (java.util.Properties)13 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)11 Patch (io.fabric8.patch.management.Patch)11 PatchException (io.fabric8.patch.management.PatchException)11 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)10 TreeMap (java.util.TreeMap)10