From c7084df4117db5a47a575ea3cc2e902114d88dc6 Mon Sep 17 00:00:00 2001 From: Jeromy Cannon Date: Wed, 27 Sep 2023 14:47:16 +0100 Subject: [PATCH] removed todo for gradle plugin logging if error and added coverage for the same Signed-off-by: Jeromy Cannon --- .../gradle/plugin/HelmInstallChartTask.java | 19 +++++++++++-------- .../plugin/HelmInstallChartTaskTest.java | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/fullstack-gradle-plugin/src/main/java/com/hedera/fullstack/gradle/plugin/HelmInstallChartTask.java b/fullstack-gradle-plugin/src/main/java/com/hedera/fullstack/gradle/plugin/HelmInstallChartTask.java index 4c5e447d3..e915e9d09 100644 --- a/fullstack-gradle-plugin/src/main/java/com/hedera/fullstack/gradle/plugin/HelmInstallChartTask.java +++ b/fullstack-gradle-plugin/src/main/java/com/hedera/fullstack/gradle/plugin/HelmInstallChartTask.java @@ -64,7 +64,6 @@ public abstract class HelmInstallChartTask extends DefaultTask { @Input @Optional @Option(option = "values", description = "Specify values in a YAML file or a URL (can specify multiple)") - // TODO: enhance to support multiple values files public abstract SetProperty getValues(); @TaskAction @@ -84,12 +83,16 @@ void installChart() { if (getValues().isPresent()) { optionsBuilder.values(new ArrayList<>(getValues().get())); } - helmClient.installChart( - getRelease().getOrNull(), - new Chart(getChart().getOrNull(), getRepo().getOrNull()), - optionsBuilder.build()); - - getProject().getLogger().info("testing..."); - // TODO log to gradle stdout if there is an error + try { + helmClient.installChart( + getRelease().getOrNull(), + new Chart(getChart().getOrNull(), getRepo().getOrNull()), + optionsBuilder.build()); + } catch (Exception e) { + this.getProject() + .getLogger() + .error("HelmInstallChartTask.installChart() An ERROR occurred while installing the chart: ", e); + throw e; + } } } 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 56f7f9aab..d99defff1 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 @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.*; import com.hedera.fullstack.helm.client.HelmClient; +import com.hedera.fullstack.helm.client.HelmExecutionException; import com.hedera.fullstack.helm.client.model.Chart; import com.hedera.fullstack.helm.client.model.Repository; import java.io.File; @@ -102,4 +103,20 @@ void testHelmInstallChartTaskSimple() { suppressExceptions(() -> helmClient.removeRepository(REPOSITORY)); } } + + @Test + @DisplayName("test an error is thrown when the chart is not found") + void testErrorThrownWhenChartNotFound() { + assertThrows(HelmExecutionException.class, () -> { + HelmInstallChartTask helmInstallChartTask = project.getTasks() + .create("helmInstallChart", HelmInstallChartTask.class, task -> { + task.getChart().set("not-a-chart"); + task.getCreateNamespace().set(true); + task.getNamespace().set("test-failure"); + task.getRelease().set("not-a-release"); + task.getRepo().set("not-a-repo"); + }); + helmInstallChartTask.installChart(); + }); + } }