-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HelmUninstallChartTask code/examples/test coverage
Signed-off-by: Jeromy Cannon <[email protected]>
- Loading branch information
1 parent
6240d28
commit c7aaf6c
Showing
4 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...radle-plugin/src/main/java/com/hedera/fullstack/gradle/plugin/HelmUninstallChartTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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 com.hedera.fullstack.helm.client.HelmClient; | ||
import com.hedera.fullstack.helm.client.HelmClientBuilder; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.Optional; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.api.tasks.options.Option; | ||
|
||
public abstract class HelmUninstallChartTask extends DefaultTask { | ||
@Input | ||
@Optional | ||
@Option(option = "namespace", description = "The namespace to use when installing the chart") | ||
public abstract Property<String> getNamespace(); | ||
|
||
@Input | ||
@Option(option = "release", description = "The name of the release to install") | ||
public abstract Property<String> getRelease(); | ||
|
||
@TaskAction | ||
void uninstallChart() { | ||
HelmClientBuilder helmClientBuilder = HelmClient.builder(); | ||
if (getNamespace().isPresent()) { | ||
helmClientBuilder.defaultNamespace(getNamespace().get()); | ||
} | ||
HelmClient helmClient = helmClientBuilder.build(); | ||
try { | ||
helmClient.uninstallChart(getRelease().getOrNull()); | ||
} catch (Exception e) { | ||
this.getProject() | ||
.getLogger() | ||
.error( | ||
"HelmUninstallChartTask.uninstallChart() An ERROR occurred while uninstalling the chart: ", | ||
e); | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...e-plugin/src/test/java/com/hedera/fullstack/gradle/plugin/HelmUninstallChartTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import com.hedera.fullstack.helm.client.HelmExecutionException; | ||
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 HelmUninstallChartTaskTest { | ||
private static Project project; | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
project = ProjectBuilder.builder().build(); | ||
} | ||
|
||
@Test | ||
@DisplayName("test an error is thrown when the chart is not found") | ||
void testErrorThrownWhenChartNotFound() { | ||
assertThrows(HelmExecutionException.class, () -> { | ||
HelmUninstallChartTask helmUninstallChartTask = project.getTasks() | ||
.create("helmUninstallNonExistingChartChart", HelmUninstallChartTask.class, task -> { | ||
task.getNamespace().set("test-failure"); | ||
task.getRelease().set("not-a-release"); | ||
}); | ||
helmUninstallChartTask.uninstallChart(); | ||
}); | ||
} | ||
} |