summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian Fochler <mail@christianfochler.de>2018-01-28 21:16:41 +0100
committerChristian Fochler <mail@christianfochler.de>2018-01-28 21:16:41 +0100
commitfd22fe75cadbfb203204d2cf52c4e6fb49a957bd (patch)
treec54fcdd8c268ac2d77aae2ce041c7964bf4a8f7f /tests
parent536f52fed4a22ed158681edce08211845abff985 (diff)
add tests for environment handling
Diffstat (limited to 'tests')
-rw-r--r--tests/env.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/env.rs b/tests/env.rs
new file mode 100644
index 0000000..fc93f15
--- /dev/null
+++ b/tests/env.rs
@@ -0,0 +1,38 @@
+extern crate config;
+
+use config::*;
+use std::env;
+
+#[test]
+fn test_default() {
+ env::set_var("A_B_C", "abc");
+
+ let environment = Environment::new();
+
+ assert!(environment.collect().unwrap().contains_key("a_b_c"));
+
+ env::remove_var("A_B_C");
+}
+
+#[test]
+fn test_prefix_is_removed_from_key() {
+ env::set_var("B_A_C", "abc");
+
+ let environment = Environment::with_prefix("B_");
+
+ assert!(environment.collect().unwrap().contains_key("a_c"));
+
+ env::remove_var("B_A_C");
+}
+
+#[test]
+fn test_separator_behavior() {
+ env::set_var("C_B_A", "abc");
+
+ let mut environment = Environment::with_prefix("C");
+ environment.separator("_");
+
+ assert!(environment.collect().unwrap().contains_key("b.a"));
+
+ env::remove_var("C_B_A");
+}