diff --git a/fullstack-examples/build.gradle.kts b/fullstack-examples/build.gradle.kts index 520a32d60..8149a3c2c 100644 --- a/fullstack-examples/build.gradle.kts +++ b/fullstack-examples/build.gradle.kts @@ -16,6 +16,7 @@ import com.hedera.fullstack.gradle.plugin.HelmInstallChartTask import com.hedera.fullstack.gradle.plugin.HelmReleaseExistsTask +import com.hedera.fullstack.gradle.plugin.HelmTestChartTask import com.hedera.fullstack.gradle.plugin.HelmUninstallChartTask plugins { @@ -46,7 +47,6 @@ tasks.register("helmInstallNginxChart") { namespace.set("nginx-ns") release.set("nginx-release") chart.set("oci://ghcr.io/nginxinc/charts/nginx-ingress") - skipIfExists.set(true) } tasks.register("helmUninstallNginxChart") { @@ -60,6 +60,11 @@ tasks.register("helmNginxExists") { release.set("nginx-release") } +tasks.register("helmTestNginxChart") { + namespace.set("nginx-ns") + release.set("nginx-release") +} + // This task will succeed because it only uninstalls if the release exists tasks.register("helmUninstallNotAChart") { release.set("not-a-release") @@ -69,6 +74,7 @@ tasks.register("helmUninstallNotAChart") { tasks.check { dependsOn("helmInstallNginxChart") dependsOn("helmNginxExists") + dependsOn("helmTestNginxChart") dependsOn("helmUninstallNginxChart") dependsOn("helmUninstallNotAChart") } diff --git a/fullstack-gradle-plugin/src/main/java/com/hedera/fullstack/gradle/plugin/HelmTestChartTask.java b/fullstack-gradle-plugin/src/main/java/com/hedera/fullstack/gradle/plugin/HelmTestChartTask.java index ea7c4966b..512b93b27 100644 --- a/fullstack-gradle-plugin/src/main/java/com/hedera/fullstack/gradle/plugin/HelmTestChartTask.java +++ b/fullstack-gradle-plugin/src/main/java/com/hedera/fullstack/gradle/plugin/HelmTestChartTask.java @@ -64,9 +64,7 @@ void testChart() { try { final String releaseName = getRelease().getOrNull(); Objects.requireNonNull(releaseName, "release name must be specified"); - helmClient.testChart( - releaseName, - optionsBuilder.build()); + helmClient.testChart(releaseName, optionsBuilder.build()); } catch (Exception e) { this.getProject() .getLogger() diff --git a/fullstack-gradle-plugin/src/test/java/com/hedera/fullstack/gradle/plugin/HelmInstallChartTaskTest.java b/fullstack-gradle-plugin/src/test/java/com/hedera/fullstack/gradle/plugin/HelmInstallChartTaskTest.java index 22688caa1..f5112c6c9 100644 --- a/fullstack-gradle-plugin/src/test/java/com/hedera/fullstack/gradle/plugin/HelmInstallChartTaskTest.java +++ b/fullstack-gradle-plugin/src/test/java/com/hedera/fullstack/gradle/plugin/HelmInstallChartTaskTest.java @@ -110,6 +110,14 @@ void testHelmInstallChartTaskSimple() { task.getRelease().set(RELEASE_NAME); }); helmReleaseExistsTask.releaseExists(); + HelmTestChartTask helmTestChartTask = project.getTasks() + .create("helmTestChartTask", HelmTestChartTask.class, task -> { + task.getNamespace().set(namespace); + task.getRelease().set(RELEASE_NAME); + task.getFilter().set("test"); + task.getTestTimeout().set("15m"); + }); + helmTestChartTask.testChart(); HelmUninstallChartTask helmUninstallChartTask = project.getTasks() .create("helmUninstallChart", HelmUninstallChartTask.class, task -> { task.getNamespace().set(namespace); diff --git a/fullstack-gradle-plugin/src/test/java/com/hedera/fullstack/gradle/plugin/HelmTestChartTaskTest.java b/fullstack-gradle-plugin/src/test/java/com/hedera/fullstack/gradle/plugin/HelmTestChartTaskTest.java new file mode 100644 index 000000000..e25bfbd33 --- /dev/null +++ b/fullstack-gradle-plugin/src/test/java/com/hedera/fullstack/gradle/plugin/HelmTestChartTaskTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2023 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hedera.fullstack.gradle.plugin; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.gradle.api.Project; +import org.gradle.testfixtures.ProjectBuilder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class HelmTestChartTaskTest { + private static Project project; + + @BeforeAll + static void beforeAll() { + project = ProjectBuilder.builder().build(); + } + + @Test + @DisplayName("test an error is thrown when the release is not found") + void testErrorThrownWhenReleaseNotFound() { + NullPointerException e = assertThrows(NullPointerException.class, () -> { + HelmTestChartTask helmTestChartTask = project.getTasks() + .create("helmTestChartTaskNonExistingRelease", HelmTestChartTask.class, task -> {}); + helmTestChartTask.testChart(); + }); + assertThat(e.getMessage()).isEqualTo("release name must be specified"); + } +}