mirror of
https://github.com/mbierlee/mirage-config.git
synced 2024-11-14 20:34:00 +01:00
Add env var substitution test for JSON
This commit is contained in:
parent
84220739d8
commit
72af2f322e
|
@ -130,6 +130,8 @@ ConfigDictionary loadJsonConfig(const string filePath) {
|
|||
}
|
||||
|
||||
version (unittest) {
|
||||
import std.process : environment;
|
||||
|
||||
@("Parse JSON")
|
||||
unittest {
|
||||
JSONValue serverJson = ["hostname": "hosty.com", "port": "1234"];
|
||||
|
@ -193,4 +195,17 @@ version (unittest) {
|
|||
assert(config.get("age") == "8728");
|
||||
assert(config.get("taxNumber") == null);
|
||||
}
|
||||
|
||||
@("Substitute env vars in JSON")
|
||||
unittest {
|
||||
environment["MIRAGE_TEST_APP_NAME"] = "Unittest";
|
||||
environment["MIRAGE_TEST_HOSTNAME"] = "wonkeyhost";
|
||||
environment.remove("MIRAGE_TEST_PORT");
|
||||
|
||||
auto config = loadJsonConfig("testfiles/server.json");
|
||||
|
||||
assert(config.get("server.host") == "wonkeyhost");
|
||||
assert(config.get("server.port") == "8118");
|
||||
assert(config.get("app") == "Unittest server - built with love");
|
||||
}
|
||||
}
|
||||
|
|
7
testfiles/server.json
Normal file
7
testfiles/server.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"server": {
|
||||
"host": "$MIRAGE_TEST_HOSTNAME",
|
||||
"port": "${MIRAGE_TEST_PORT:8118}"
|
||||
},
|
||||
"app": "${MIRAGE_TEST_APP_NAME} server - built with love"
|
||||
}
|
Loading…
Reference in a new issue