-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from uzzu/all-variables-or-null
DotEnvRoot#allVariables for null variables
- Loading branch information
Showing
10 changed files
with
155 additions
and
7 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
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
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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
package co.uzzu.dotenv | ||
|
||
class InMemoryEnvProvider( | ||
private val map: Map<String, String> | ||
private val map: Map<String, String?> | ||
) : EnvProvider { | ||
override fun getenv(name: String): String? = map[name] | ||
|
||
override fun getenv(): Map<String, String> = map | ||
.mapNotNull { (key, value) -> value?.let { key to it } } | ||
.toMap() | ||
|
||
override fun getenvOrNull(): Map<String, String?> = map.toMap() | ||
} |
48 changes: 48 additions & 0 deletions
48
plugin/src/test/kotlin/co/uzzu/dotenv/gradle/AllVariablesOrNullTest.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,48 @@ | ||
package co.uzzu.dotenv.gradle | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.contains | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.io.TempDir | ||
import java.io.File | ||
|
||
class AllVariablesOrNullTest { | ||
|
||
@TempDir | ||
lateinit var projectDir: File | ||
|
||
@Test | ||
fun nullValuesDefinedByTemplate() { | ||
RootProject(projectDir) { | ||
settingsGradle() | ||
buildGradle( | ||
""" | ||
plugins { | ||
base | ||
id("co.uzzu.dotenv.gradle") | ||
} | ||
println("Result: ${'$'}{env.allVariablesOrNull().filterKeys { it == "HOGE" }}") | ||
""".trimIndent() | ||
) | ||
file( | ||
".env.template", | ||
""" | ||
HOGE= | ||
""".trimIndent() | ||
) | ||
file( | ||
".env", | ||
""" | ||
""".trimIndent() | ||
) | ||
} | ||
|
||
val result = GradleRunner.create() | ||
.withPluginClasspath() | ||
.withProjectDir(projectDir) | ||
.build() | ||
|
||
assertThat(result.output).contains("Result: {HOGE=null}") | ||
} | ||
} |
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