mirror of
https://github.com/lightbend/config.git
synced 2025-02-22 17:20:34 +08:00
fix tests to run on windows
This commit is contained in:
parent
4463001e1c
commit
805936f312
@ -294,7 +294,7 @@ class ConfigDocumentTest extends TestUtils {
|
||||
val configDocument = ConfigDocumentFactory.parseFile(resourceFile("/test03.conf"))
|
||||
val fileReader = new BufferedReader(new FileReader("config/src/test/resources/test03.conf"))
|
||||
var line = fileReader.readLine()
|
||||
var sb = new StringBuilder()
|
||||
val sb = new StringBuilder()
|
||||
while (line != null) {
|
||||
sb.append(line)
|
||||
sb.append("\n")
|
||||
@ -302,9 +302,11 @@ class ConfigDocumentTest extends TestUtils {
|
||||
}
|
||||
fileReader.close()
|
||||
val fileText = sb.toString()
|
||||
assertEquals(fileText, configDocument.render())
|
||||
assertEquals(fileText, defaultLineEndingsToUnix(configDocument.render()))
|
||||
}
|
||||
|
||||
private def defaultLineEndingsToUnix(s: String): String = s.replaceAll(System.lineSeparator(), "\n")
|
||||
|
||||
@Test
|
||||
def configDocumentReaderParse {
|
||||
val configDocument = ConfigDocumentFactory.parseReader(new FileReader(resourceFile("/test03.conf")))
|
||||
|
@ -739,14 +739,17 @@ class ConfigSubstitutionTest extends TestUtils {
|
||||
}
|
||||
|
||||
private val substEnvVarObject = {
|
||||
// prefix the names of keys with "key_" to allow us to embed a case sensitive env var name
|
||||
// in the key that wont therefore risk a naming collision with env vars themselves
|
||||
parseObject("""
|
||||
{
|
||||
"home" : ${?HOME},
|
||||
"pwd" : ${?PWD},
|
||||
"shell" : ${?SHELL},
|
||||
"lang" : ${?LANG},
|
||||
"path" : ${?PATH},
|
||||
"not_here" : ${?NOT_HERE}
|
||||
"key_HOME" : ${?HOME},
|
||||
"key_PWD" : ${?PWD},
|
||||
"key_SHELL" : ${?SHELL},
|
||||
"key_LANG" : ${?LANG},
|
||||
"key_PATH" : ${?PATH},
|
||||
"key_Path" : ${?Path}, // many windows machines use Path rather than PATH
|
||||
"key_NOT_HERE" : ${?NOT_HERE}
|
||||
}
|
||||
""")
|
||||
}
|
||||
@ -759,7 +762,8 @@ class ConfigSubstitutionTest extends TestUtils {
|
||||
|
||||
var existed = 0
|
||||
for (k <- resolved.root.keySet().asScala) {
|
||||
val e = System.getenv(k.toUpperCase());
|
||||
val envVarName = k.replace("key_", "")
|
||||
val e = System.getenv(envVarName)
|
||||
if (e != null) {
|
||||
existed += 1
|
||||
assertEquals(e, resolved.getString(k))
|
||||
@ -782,7 +786,8 @@ class ConfigSubstitutionTest extends TestUtils {
|
||||
// { HOME : null } then ${HOME} should be null.
|
||||
val nullsMap = new java.util.HashMap[String, Object]
|
||||
for (k <- substEnvVarObject.keySet().asScala) {
|
||||
nullsMap.put(k.toUpperCase(), null);
|
||||
val envVarName = k.replace("key_", "")
|
||||
nullsMap.put(envVarName, null)
|
||||
}
|
||||
val nulls = ConfigFactory.parseMap(nullsMap, "nulls map")
|
||||
|
||||
@ -802,11 +807,12 @@ class ConfigSubstitutionTest extends TestUtils {
|
||||
|
||||
values.put("a", substEnvVarObject.relativized(new Path("a")))
|
||||
|
||||
val resolved = resolve(new SimpleConfigObject(fakeOrigin(), values));
|
||||
val resolved = resolve(new SimpleConfigObject(fakeOrigin(), values))
|
||||
|
||||
var existed = 0
|
||||
for (k <- resolved.getObject("a").keySet().asScala) {
|
||||
val e = System.getenv(k.toUpperCase());
|
||||
val envVarName = k.replace("key_", "")
|
||||
val e = System.getenv(envVarName)
|
||||
if (e != null) {
|
||||
existed += 1
|
||||
assertEquals(e, resolved.getConfig("a").getString(k))
|
||||
|
@ -858,7 +858,7 @@ class ConfigTest extends TestUtils {
|
||||
if (home != null) {
|
||||
assertEquals(home, conf.getString("system.home"))
|
||||
} else {
|
||||
assertEquals(nullValue, conf.getObject("system").get("home"))
|
||||
assertEquals(null, conf.getObject("system").get("home"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -964,7 +964,7 @@ class ConfigTest extends TestUtils {
|
||||
if (home != null) {
|
||||
assertEquals(home, conf.getString("test01.system.home"))
|
||||
} else {
|
||||
assertEquals(nullValue, conf.getObject("test01.system").get("home"))
|
||||
assertEquals(null, conf.getObject("test01.system").get("home"))
|
||||
}
|
||||
val concatenated = conf.getString("test01.system.concatenated")
|
||||
assertTrue(concatenated.contains("Your Java version"))
|
||||
|
Loading…
Reference in New Issue
Block a user