forked from unbroken-dome/gradle-helm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementation, documentation, unit tests
- Loading branch information
1 parent
053b573
commit cb3e7bd
Showing
24 changed files
with
341 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
*.iml | ||
out/ | ||
|
||
# Visual Studio Code | ||
.vscode/ | ||
|
||
# Gradle | ||
.gradle/ | ||
build/ | ||
|
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
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
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
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
57 changes: 57 additions & 0 deletions
57
...src/functionalTest/kotlin/com/citi/gradle/plugins/helm/tests/functional/HelmExecutable.kt
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,57 @@ | ||
package com.citi.gradle.plugins.helm.tests.functional | ||
|
||
import java.io.File | ||
|
||
/** | ||
* Helping class creating helm executable that does nothing | ||
* | ||
* Is needed to simulate real helm (we don't need to verify this) and ignore actions done by other parts of a plugin. | ||
*/ | ||
|
||
internal object HelmExecutable { | ||
private val helmExecutablesDirectory = File("./src/functionalTest/resources/executable") | ||
private val fileExtension = let { | ||
val isWindows = System.getProperty("os.name").contains("Windows", ignoreCase = true) | ||
|
||
if (isWindows) { | ||
"bat" | ||
} else { | ||
"sh" | ||
} | ||
} | ||
|
||
private val executableDummyHelm = helmExecutablesDirectory.resolve("helm.$fileExtension") | ||
|
||
/** | ||
* 2. Creates gradle parameter with path to that executable | ||
*/ | ||
fun getExecutableParameterForHelm( | ||
temporaryFolder: File | ||
): HelmExecutableParameter { | ||
|
||
val destinationExecutableFile = temporaryFolder.resolve("helm.$fileExtension") | ||
|
||
executableDummyHelm.copyTo(destinationExecutableFile) | ||
destinationExecutableFile.setExecutable(true) | ||
|
||
return HelmExecutableParameter(destinationExecutableFile) | ||
} | ||
|
||
private fun getAbsoluteNormalizedPath(file: File): String { | ||
return file | ||
.absoluteFile | ||
.normalize() | ||
.path | ||
.replace('\\', '/') | ||
} | ||
|
||
internal class HelmExecutableParameter( | ||
path: File | ||
) { | ||
val parameterValue = let { | ||
val normalizedFilePath = getAbsoluteNormalizedPath(path) | ||
|
||
"-Phelm.executable=${normalizedFilePath}" | ||
} | ||
} | ||
} |
159 changes: 159 additions & 0 deletions
159
...st/kotlin/com/citi/gradle/plugins/helm/tests/functional/SuppressEnvironmentLoggingTest.kt
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,159 @@ | ||
package com.citi.gradle.plugins.helm.tests.functional | ||
|
||
import com.citi.gradle.plugins.helm.plugin.test.utils.DefaultGradleRunnerParameters | ||
import com.citi.gradle.plugins.helm.plugin.test.utils.GradleRunnerProvider | ||
import io.kotest.matchers.string.shouldContain | ||
import io.kotest.matchers.string.shouldNotContain | ||
import java.io.File | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.io.TempDir | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.MethodSource | ||
|
||
internal class SuppressEnvironmentLoggingTest { | ||
|
||
private val sourceDirectory = File("./src/functionalTest/resources/test/suppress-environment-logging") | ||
|
||
@TempDir | ||
private lateinit var testProjectDir: File | ||
|
||
@BeforeEach | ||
fun setup() { | ||
sourceDirectory.copyRecursively(target = testProjectDir) | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("com.citi.gradle.plugins.helm.plugin.test.utils.DefaultGradleRunnerParameters#getDefaultParameterSet") | ||
fun doNotSuppressEnvironmentLoggingByDefault(parameters: DefaultGradleRunnerParameters) { | ||
// given | ||
|
||
selectBuildGradle("without-suppress") | ||
|
||
val helmExecutableParameter = | ||
HelmExecutable.getExecutableParameterForHelm(testProjectDir) | ||
|
||
val arguments = listOf( | ||
"helmPackage", | ||
"--info", | ||
helmExecutableParameter.parameterValue | ||
) | ||
|
||
val gradleRunner = GradleRunnerProvider | ||
.createRunner(parameters) | ||
.withProjectDir(testProjectDir) | ||
.withArguments(arguments) | ||
|
||
// when | ||
val result = gradleRunner.build() | ||
|
||
// then | ||
val output = result.output | ||
|
||
output shouldContain "BUILD SUCCESSFUL" | ||
output shouldContain "with environment:" | ||
output shouldNotContain "(environment logging is suppressed)" | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("com.citi.gradle.plugins.helm.plugin.test.utils.DefaultGradleRunnerParameters#getDefaultParameterSet") | ||
fun suppressEnvironmentLoggingWithCommandLineProperty(parameters: DefaultGradleRunnerParameters) { | ||
// given | ||
|
||
selectBuildGradle("without-suppress") | ||
|
||
val helmExecutableParameter = | ||
HelmExecutable.getExecutableParameterForHelm(testProjectDir) | ||
|
||
val arguments = listOf( | ||
"helmPackage", | ||
"--info", | ||
"-Phelm.suppressEnvironmentLogging=true", | ||
helmExecutableParameter.parameterValue | ||
) | ||
|
||
val gradleRunner = GradleRunnerProvider | ||
.createRunner(parameters) | ||
.withProjectDir(testProjectDir) | ||
.withArguments(arguments) | ||
|
||
// when | ||
val result = gradleRunner.build() | ||
|
||
// then | ||
val output = result.output | ||
|
||
output shouldContain "BUILD SUCCESSFUL" | ||
output shouldContain "(environment logging is suppressed)" | ||
output shouldNotContain "with environment:" | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("com.citi.gradle.plugins.helm.plugin.test.utils.DefaultGradleRunnerParameters#getDefaultParameterSet") | ||
fun doNotSuppressEnvironmentLoggingWithCommandLineProperty(parameters: DefaultGradleRunnerParameters) { | ||
// given | ||
|
||
selectBuildGradle("without-suppress") | ||
|
||
val helmExecutableParameter = | ||
HelmExecutable.getExecutableParameterForHelm(testProjectDir) | ||
|
||
val arguments = listOf( | ||
"helmPackage", | ||
"--info", | ||
"-Phelm.suppressEnvironmentLogging=false", | ||
helmExecutableParameter.parameterValue | ||
) | ||
|
||
val gradleRunner = GradleRunnerProvider | ||
.createRunner(parameters) | ||
.withProjectDir(testProjectDir) | ||
.withArguments(arguments) | ||
|
||
// when | ||
val result = gradleRunner.build() | ||
|
||
// then | ||
val output = result.output | ||
|
||
output shouldContain "BUILD SUCCESSFUL" | ||
output shouldContain "with environment:" | ||
output shouldNotContain "(environment logging is suppressed)" | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("com.citi.gradle.plugins.helm.plugin.test.utils.DefaultGradleRunnerParameters#getDefaultParameterSet") | ||
fun suppressEnvironmentLoggingWithDsl(parameters: DefaultGradleRunnerParameters) { | ||
// given | ||
|
||
selectBuildGradle("with-suppress") | ||
|
||
val helmExecutableParameter = | ||
HelmExecutable.getExecutableParameterForHelm(testProjectDir) | ||
|
||
val arguments = listOf( | ||
"helmPackage", | ||
"--info", | ||
helmExecutableParameter.parameterValue | ||
) | ||
|
||
val gradleRunner = GradleRunnerProvider | ||
.createRunner(parameters) | ||
.withProjectDir(testProjectDir) | ||
.withArguments(arguments) | ||
|
||
// when | ||
val result = gradleRunner.build() | ||
|
||
// then | ||
val output = result.output | ||
|
||
output shouldContain "BUILD SUCCESSFUL" | ||
output shouldContain "(environment logging is suppressed)" | ||
output shouldNotContain "with environment:" | ||
} | ||
|
||
private fun selectBuildGradle(selection: String) { | ||
File(testProjectDir, "build.gradle.$selection") | ||
.copyTo(File(testProjectDir, "build.gradle")) | ||
} | ||
} |
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 @@ | ||
rem Dummy executable just to simulate real helm |
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 @@ | ||
# Dummy executable just to simulate real helm |
7 changes: 7 additions & 0 deletions
7
...src/functionalTest/resources/test/suppress-environment-logging/build.gradle.with-suppress
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,7 @@ | ||
plugins { | ||
id 'com.citi.helm' | ||
} | ||
|
||
helm { | ||
suppressEnvironmentLogging = true | ||
} |
3 changes: 3 additions & 0 deletions
3
.../functionalTest/resources/test/suppress-environment-logging/build.gradle.without-suppress
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,3 @@ | ||
plugins { | ||
id 'com.citi.helm' | ||
} |
Empty file.
6 changes: 6 additions & 0 deletions
6
...n/src/functionalTest/resources/test/suppress-environment-logging/src/main/helm/Chart.yaml
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,6 @@ | ||
apiVersion: v2 | ||
name: dummy | ||
description: A dummy helm chart | ||
version: 0.0.1 | ||
appVersion: "0.0.1" | ||
type: application |
10 changes: 10 additions & 0 deletions
10
...nctionalTest/resources/test/suppress-environment-logging/src/main/helm/templates/pod.yaml
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,10 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:1.14.2 | ||
ports: | ||
- containerPort: 80 |
1 change: 1 addition & 0 deletions
1
.../src/functionalTest/resources/test/suppress-environment-logging/src/main/helm/values.yaml
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 @@ | ||
# dummy |
Oops, something went wrong.