diff --git a/it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfig.java b/it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfig.java new file mode 100644 index 00000000..ecf2032e --- /dev/null +++ b/it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfig.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2019 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at: + * + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.jkube.integrationtests.springboot.helmconfig; + +import io.fabric8.junit.jupiter.api.KubernetesTest; +import io.fabric8.kubernetes.client.KubernetesClient; +import org.eclipse.jkube.integrationtests.JKubeCase; +import org.eclipse.jkube.integrationtests.maven.MavenCase; + +@KubernetesTest(createEphemeralNamespace = false) +abstract class HelmConfig implements JKubeCase, MavenCase { + private static final String PROJECT_HELM = "projects-to-be-tested/maven/spring/helm-config"; + + private static KubernetesClient kubernetesClient; + + @Override + public KubernetesClient getKubernetesClient() { + return kubernetesClient; + } + + @Override + public String getProject() { + return PROJECT_HELM; + } +} diff --git a/it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfigK8sITCase.java b/it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfigK8sITCase.java new file mode 100644 index 00000000..3757e3c7 --- /dev/null +++ b/it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfigK8sITCase.java @@ -0,0 +1,163 @@ +/** + * Copyright (c) 2019 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at: + * + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.jkube.integrationtests.springboot.helmconfig; + +import org.apache.maven.shared.invoker.InvocationResult; +import org.eclipse.jkube.integrationtests.jupiter.api.DockerRegistry; +import org.eclipse.jkube.integrationtests.jupiter.api.DockerRegistryHost; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.util.Properties; + +import static org.eclipse.jkube.integrationtests.Tags.KUBERNETES; +import static org.eclipse.jkube.integrationtests.assertions.InvocationResultAssertion.assertInvocation; +import static org.eclipse.jkube.integrationtests.assertions.YamlAssertion.yaml; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.aMapWithSize; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anEmptyMap; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; + +@DockerRegistry(port = 5080) +@Tag(KUBERNETES) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class HelmConfigK8sITCase extends HelmConfig { + + @DockerRegistryHost + protected String registry; + + @Test + @Order(1) + @DisplayName("k8s:resource, no specified profile, should create default resource manifests") + void k8sResource() throws Exception { + // When + final InvocationResult invocationResult = maven("k8s:resource"); + // Then + assertInvocation(invocationResult); + } + + @Test + @Order(2) + @DisplayName("k8s:helm, should create Helm charts") + void k8sHelm() throws Exception { + // When + final InvocationResult invocationResult = maven("k8s:helm"); + // Then + assertInvocation(invocationResult); + assertThat(new File(String.format("../%s/target/jkube/helm/the-chart-name/kubernetes/the-chart-name-1.0-KUBERNETES.tar", getProject())) + .exists(), equalTo(true)); + final File helmDirectory = new File( + String.format("../%s/target/jkube/helm/the-chart-name/kubernetes", getProject())); + assertThat(new File(helmDirectory, "Chart.yaml"), yaml(allOf( + aMapWithSize(10), + hasEntry("apiVersion", "v1"), + hasEntry("name", "the-chart-name"), + hasEntry("version", "1.0-KUBERNETES"), + hasEntry("description", "Description different to that in the pom.xml"), + hasEntry("home", "https://www.home.example.com"), + hasEntry("engine", "v8") + ))); + assertThat(new File(helmDirectory, "Chart.yaml"), yaml(allOf( + hasEntry(is("sources"), contains("https://source.1.example.com")), + hasEntry(is("keywords"), containsInAnyOrder("key", "words", "comma", "separated")) + ))); + assertThat(new File(helmDirectory, "Chart.yaml"), yaml( + hasEntry(is("maintainers"), contains(allOf( + hasEntry("name", "Mr. Ed"), + hasEntry("email", "ed@example.com") + ))) + )); + assertThat(new File(helmDirectory, "values.yaml"), yaml(anEmptyMap())); + assertThat(new File(helmDirectory, "templates/spring-boot-helm-config-deployment.yaml"), yaml(not(anEmptyMap()))); + assertThat(new File(helmDirectory, "templates/spring-boot-helm-config-service.yaml"), yaml(not(anEmptyMap()))); + } + + @Test + @Order(3) + @DisplayName("k8s:helm-push, should push the charts") + void k8sHelmPush() throws Exception { + // Given + final Properties properties = properties( + "jkube.helm.stableRepository.type", "OCI", + "jkube.helm.stableRepository.name", "docker", + "jkube.helm.stableRepository.url", "oci://" + registry, + "jkube.helm.stableRepository.username", "ignored", + "jkube.helm.stableRepository.password", "ignored" + ); + // When + final InvocationResult invocationResult = maven("k8s:helm-push", properties); + // Then + assertInvocation(invocationResult); + assertThat(httpGet("http://" + registry + "/v2/the-chart-name/tags/list").body(), + containsString("{\"name\":\"the-chart-name\",\"tags\":[\"1.0-KUBERNETES\"]}")); + } + + @Test + @DisplayName("k8s:helm-uninstall, no release present, display error message") + void k8sHelmUninstall_whenNoReleasePresent_thenErrorMessageDisplayed() throws Exception { + // Given + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + // When + maven("k8s:helm-uninstall", properties("jkube.helm.release.name", "spring-boot-helm-config-k8s-does-not-exist"), byteArrayOutputStream); + // Then + assertThat(byteArrayOutputStream.toString(), allOf( + containsString("helm-uninstall failed"), + containsString("uninstall: Release not loaded: spring-boot-helm-config-k8s-does-not-exist: release: not found") + )); + } + + @Test + @Order(4) + @DisplayName("k8s:helm-install, should install the charts") + void k8sHelmInstall() throws Exception { + // Given + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + // When + maven("k8s:helm-install", properties("jkube.helm.release.name", "spring-boot-helm-config-k8s"), byteArrayOutputStream); + // Then + assertThat(byteArrayOutputStream.toString(), + allOf(containsString("Installing Helm Chart the-chart-name 1.0-KUBERNETES"), + containsString("NAME : spring-boot-helm-config-k8s"), + containsString("NAMESPACE : "), + containsString("STATUS : deployed"), + containsString("REVISION : 1"))); + } + + @Test + @Order(5) + @DisplayName("k8s:helm-uninstall, should uninstall the charts") + void k8sHelmUninstall() throws Exception { + // Given + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + // When + maven("k8s:helm-uninstall", properties("jkube.helm.release.name", "spring-boot-helm-config-k8s"), byteArrayOutputStream); + // Then + assertThat(byteArrayOutputStream.toString(), + allOf(containsString("Uninstalling Helm Chart the-chart-name 1.0-KUBERNETES"), + containsString("release \"spring-boot-helm-config-k8s\" uninstalled"))); + } +} diff --git a/it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfigITCase.java b/it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfigOcITCase.java similarity index 57% rename from it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfigITCase.java rename to it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfigOcITCase.java index 11fd69dd..1a4276ba 100644 --- a/it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfigITCase.java +++ b/it/src/test/java/org/eclipse/jkube/integrationtests/springboot/helmconfig/HelmConfigOcITCase.java @@ -14,12 +14,9 @@ package org.eclipse.jkube.integrationtests.springboot.helmconfig; import io.fabric8.junit.jupiter.api.KubernetesTest; -import io.fabric8.kubernetes.client.KubernetesClient; import org.apache.maven.shared.invoker.InvocationResult; -import org.eclipse.jkube.integrationtests.JKubeCase; import org.eclipse.jkube.integrationtests.jupiter.api.DockerRegistry; import org.eclipse.jkube.integrationtests.jupiter.api.DockerRegistryHost; -import org.eclipse.jkube.integrationtests.maven.MavenCase; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; @@ -27,10 +24,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; +import java.io.ByteArrayOutputStream; import java.io.File; import java.util.Properties; -import static org.eclipse.jkube.integrationtests.Tags.KUBERNETES; import static org.eclipse.jkube.integrationtests.Tags.OPEN_SHIFT; import static org.eclipse.jkube.integrationtests.Tags.OPEN_SHIFT_OSCI; import static org.eclipse.jkube.integrationtests.assertions.InvocationResultAssertion.assertInvocation; @@ -40,49 +37,23 @@ import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.anEmptyMap; import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; +@Tag(OPEN_SHIFT) +@Tag(OPEN_SHIFT_OSCI) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @DockerRegistry(port = 5080) -@KubernetesTest(createEphemeralNamespace = false) -class HelmConfigITCase implements JKubeCase, MavenCase { - - private static final String PROJECT_HELM = "projects-to-be-tested/maven/spring/helm-config"; - - private static KubernetesClient kubernetesClient; +class HelmConfigOcITCase extends HelmConfig { @DockerRegistryHost - private String registry; - - @Override - public KubernetesClient getKubernetesClient() { - return kubernetesClient; - } - @Override - public String getProject() { - return PROJECT_HELM; - } - - @Test - @Order(1) - @Tag(KUBERNETES) - @DisplayName("k8s:resource, no specified profile, should create default resource manifests") - void k8sResource() throws Exception { - // When - final InvocationResult invocationResult = maven("k8s:resource"); - // Then - assertInvocation(invocationResult); - } + protected String registry; @Test @Order(1) - @Tag(OPEN_SHIFT) - @Tag(OPEN_SHIFT_OSCI) @DisplayName("oc:resource, no specified profile, should create default resource manifests") void ocResource() throws Exception { // When @@ -93,45 +64,6 @@ void ocResource() throws Exception { @Test @Order(2) - @Tag(KUBERNETES) - @DisplayName("k8s:helm, should create Helm charts") - void k8sHelm() throws Exception { - // When - final InvocationResult invocationResult = maven("k8s:helm"); - // Then - assertInvocation(invocationResult); - assertThat(new File(String.format("../%s/target/jkube/helm/the-chart-name/kubernetes/the-chart-name-1.0-KUBERNETES.tar", getProject())) - .exists(), equalTo(true)); - final File helmDirectory = new File( - String.format("../%s/target/jkube/helm/the-chart-name/kubernetes", getProject())); - assertThat(new File(helmDirectory, "Chart.yaml"), yaml(allOf( - aMapWithSize(10), - hasEntry("apiVersion", "v1"), - hasEntry("name", "the-chart-name"), - hasEntry("version", "1.0-KUBERNETES"), - hasEntry("description", "Description different to that in the pom.xml"), - hasEntry("home", "https://www.home.example.com"), - hasEntry("engine", "v8") - ))); - assertThat(new File(helmDirectory, "Chart.yaml"), yaml(allOf( - hasEntry(is("sources"), contains("https://source.1.example.com")), - hasEntry(is("keywords"), containsInAnyOrder("key", "words", "comma", "separated")) - ))); - assertThat(new File(helmDirectory, "Chart.yaml"), yaml( - hasEntry(is("maintainers"), contains(allOf( - hasEntry("name", "Mr. Ed"), - hasEntry("email", "ed@example.com") - ))) - )); - assertThat(new File(helmDirectory, "values.yaml"), yaml(anEmptyMap())); - assertThat(new File(helmDirectory, "templates/spring-boot-helm-config-deployment.yaml"), yaml(not(anEmptyMap()))); - assertThat(new File(helmDirectory, "templates/spring-boot-helm-config-service.yaml"), yaml(not(anEmptyMap()))); - } - - @Test - @Order(2) - @Tag(OPEN_SHIFT) - @Tag(OPEN_SHIFT_OSCI) @DisplayName("oc:helm, should create Helm charts") void ocHelm() throws Exception { // When @@ -168,9 +100,8 @@ void ocHelm() throws Exception { @Test @Order(3) - @Tag(KUBERNETES) - @DisplayName("k8s:helm-push, should push the charts") - void k8sHelmPush() throws Exception { + @DisplayName("oc:helm-push, should push the charts") + void ocHelmPush() throws Exception { // Given final Properties properties = properties( "jkube.helm.stableRepository.type", "OCI", @@ -180,32 +111,55 @@ void k8sHelmPush() throws Exception { "jkube.helm.stableRepository.password", "ignored" ); // When - final InvocationResult invocationResult = maven("k8s:helm-push", properties); + final InvocationResult invocationResult = maven("oc:helm-push", properties); // Then assertInvocation(invocationResult); - assertThat(httpGet("http://" + registry + "/v2/the-chart-name/tags/list").body(), - containsString("{\"name\":\"the-chart-name\",\"tags\":[\"1.0-KUBERNETES\"]}")); + assertThat(httpGet("http://" + registry + "/v2/different-name-for-oc/tags/list").body(), + containsString("{\"name\":\"different-name-for-oc\",\"tags\":[\"0.1-OC\"]}")); } @Test - @Order(3) - @Tag(OPEN_SHIFT) - @Tag(OPEN_SHIFT_OSCI) - @DisplayName("oc:helm-push, should push the charts") - void ocHelmPush() throws Exception { + @DisplayName("oc:helm-uninstall, no release present, display error message") + void ocHelmUninstall_whenNoReleasePresent_thenErrorMessageDisplayed() throws Exception { // Given - final Properties properties = properties( - "jkube.helm.stableRepository.type", "OCI", - "jkube.helm.stableRepository.name", "docker", - "jkube.helm.stableRepository.url", "oci://" + registry, - "jkube.helm.stableRepository.username", "ignored", - "jkube.helm.stableRepository.password", "ignored" - ); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); // When - final InvocationResult invocationResult = maven("oc:helm-push", properties); + maven("oc:helm-uninstall", properties("jkube.helm.release.name", "spring-boot-helm-config-oc-does-not-exist"), byteArrayOutputStream); // Then - assertInvocation(invocationResult); - assertThat(httpGet("http://" + registry + "/v2/different-name-for-oc/tags/list").body(), - containsString("{\"name\":\"different-name-for-oc\",\"tags\":[\"0.1-OC\"]}")); + assertThat(byteArrayOutputStream.toString(), allOf( + containsString("helm-uninstall failed"), + containsString("uninstall: Release not loaded: spring-boot-helm-config-oc-does-not-exist: release: not found") + )); + } + + @Test + @Order(4) + @DisplayName("oc:helm-install, should install the charts") + void ocHelmInstall() throws Exception { + // Given + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + // When + maven("oc:helm-install", properties("jkube.helm.release.name", "spring-boot-helm-config-oc"), byteArrayOutputStream); + // Then + assertThat(byteArrayOutputStream.toString(), + allOf(containsString("Installing Helm Chart different-name-for-oc 0.1-OC"), + containsString("NAME : spring-boot-helm-config-oc"), + containsString("NAMESPACE : "), + containsString("STATUS : deployed"), + containsString("REVISION : 1"))); + } + + @Test + @Order(5) + @DisplayName("oc:helm-uninstall, should uninstall the charts") + void ocHelmUninstall() throws Exception { + // Given + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + // When + maven("oc:helm-uninstall", properties("jkube.helm.release.name", "spring-boot-helm-config-oc"), byteArrayOutputStream); + // Then + assertThat(byteArrayOutputStream.toString(), + allOf(containsString("Uninstalling Helm Chart different-name-for-oc 0.1-OC"), + containsString("release \"spring-boot-helm-config-oc\" uninstalled"))); } }