Skip to content

Commit

Permalink
test coverage and example
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon committed Oct 17, 2023
1 parent da0f175 commit 4c07898
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
8 changes: 7 additions & 1 deletion fullstack-examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -46,7 +47,6 @@ tasks.register<HelmInstallChartTask>("helmInstallNginxChart") {
namespace.set("nginx-ns")
release.set("nginx-release")
chart.set("oci://ghcr.io/nginxinc/charts/nginx-ingress")
skipIfExists.set(true)
}

tasks.register<HelmUninstallChartTask>("helmUninstallNginxChart") {
Expand All @@ -60,6 +60,11 @@ tasks.register<HelmReleaseExistsTask>("helmNginxExists") {
release.set("nginx-release")
}

tasks.register<HelmTestChartTask>("helmTestNginxChart") {
namespace.set("nginx-ns")
release.set("nginx-release")
}

// This task will succeed because it only uninstalls if the release exists
tasks.register<HelmUninstallChartTask>("helmUninstallNotAChart") {
release.set("not-a-release")
Expand All @@ -69,6 +74,7 @@ tasks.register<HelmUninstallChartTask>("helmUninstallNotAChart") {
tasks.check {
dependsOn("helmInstallNginxChart")
dependsOn("helmNginxExists")
dependsOn("helmTestNginxChart")
dependsOn("helmUninstallNginxChart")
dependsOn("helmUninstallNotAChart")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}

0 comments on commit 4c07898

Please sign in to comment.