Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcruzdev committed Mar 29, 2024
1 parent ada9496 commit b4728ff
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.quarkus.it.kubernetes;

import io.fabric8.kubernetes.api.model.ConfigMapEnvSource;
import io.fabric8.kubernetes.api.model.EnvFromSource;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.quarkus.test.ProdBuildResults;
import io.quarkus.test.ProdModeTestResults;
import io.quarkus.test.QuarkusProdModeTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class KubernetesWithEnvFromConfigMapWithPrefixBehaviorsTest {

@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class))
.setApplicationName("env-from-config-map-with-prefix-behaviors")
.setApplicationVersion("0.1-SNAPSHOT")
.withConfigurationResource("kubernetes-with-env-from-config-map-with-prefix-behaviors.properties");

@ProdBuildResults
private ProdModeTestResults prodModeTestResults;

@Test
public void assertGeneratedResources() throws IOException {
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
assertThat(kubernetesDir)
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json"))
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml"));
List<HasMetadata> kubernetesList = DeserializationUtil
.deserializeAsList(kubernetesDir.resolve("kubernetes.yml"));
assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Deployment.class, d -> {
assertThat(d.getMetadata()).satisfies(m -> {
assertThat(m.getName()).isEqualTo("env-from-config-map-with-prefix-behaviors");
});

assertThat(d.getSpec()).satisfies(deploymentSpec -> {
assertThat(deploymentSpec.getTemplate()).satisfies(t -> {
assertThat(t.getSpec()).satisfies(podSpec -> {
assertThat(podSpec.getContainers()).singleElement().satisfies(container -> {

assertThat(container.getEnvFrom()).containsExactlyInAnyOrder(
new EnvFromSource(
new ConfigMapEnvSource("another", true), "QUARKUS", null
),
new EnvFromSource(
new ConfigMapEnvSource("without", true), null, null
),
new EnvFromSource(
new ConfigMapEnvSource("configmap", true), "HELLO", null
)
);
});
});
});
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.quarkus.it.kubernetes;

import io.fabric8.kubernetes.api.model.ConfigMapEnvSource;
import io.fabric8.kubernetes.api.model.EnvFromSource;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.SecretEnvSource;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.quarkus.test.ProdBuildResults;
import io.quarkus.test.ProdModeTestResults;
import io.quarkus.test.QuarkusProdModeTest;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class KubernetesWithEnvFromSecretWithPrefixBehaviorsTest {

@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class))
.setApplicationName("env-from-secret-with-prefix")
.setApplicationVersion("0.1-SNAPSHOT")
.withConfigurationResource("kubernetes-with-env-from-secret-with-prefix-behaviors.properties");

@ProdBuildResults
private ProdModeTestResults prodModeTestResults;

@Test
public void assertGeneratedResources() throws IOException {
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
assertThat(kubernetesDir)
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json"))
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml"));
List<HasMetadata> kubernetesList = DeserializationUtil
.deserializeAsList(kubernetesDir.resolve("kubernetes.yml"));
assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Deployment.class, d -> {
assertThat(d.getMetadata()).satisfies(m -> {
assertThat(m.getName()).isEqualTo("env-from-secret-with-prefix-behaviors");
});

assertThat(d.getSpec()).satisfies(deploymentSpec -> {
assertThat(deploymentSpec.getTemplate()).satisfies(t -> {
assertThat(t.getSpec()).satisfies(podSpec -> {
assertThat(podSpec.getContainers()).singleElement().satisfies(container -> {
assertThat(container.getEnvFrom()).containsExactlyInAnyOrder(
new EnvFromSource(
null, "QUARKUS", new SecretEnvSource("another", true)
),
new EnvFromSource(
null, "HELLO", new SecretEnvSource("secrets", true)
),
new EnvFromSource(
null, null, new SecretEnvSource("without", true)
));
});
});
});
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quarkus.kubernetes.configmaps.secrets=configmap[PREFIX],another[QUARKUS][ANOTHER],configmap[HELLO],without
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quarkus.kubernetes.env.secrets=secrets[PREFIX],another[QUARKUS][ANOTHER],secrets[HELLO],without

0 comments on commit b4728ff

Please sign in to comment.