summaryrefslogtreecommitdiffstats
path: root/tests/env.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/env.rs')
-rw-r--r--tests/env.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/env.rs b/tests/env.rs
index 3a24bde..a144d08 100644
--- a/tests/env.rs
+++ b/tests/env.rs
@@ -464,6 +464,61 @@ fn test_parse_string_and_list() {
}
#[test]
+fn test_parse_nested_kebab() {
+ use config::Case;
+
+ #[derive(Deserialize, Debug)]
+ #[serde(rename_all = "kebab-case")]
+ struct TestConfig {
+ single: String,
+ plain: SimpleInner,
+ value_with_multipart_name: String,
+ inner_config: ComplexInner,
+ }
+
+ #[derive(Deserialize, Debug)]
+ #[serde(rename_all = "kebab-case")]
+ struct SimpleInner {
+ val: String,
+ }
+
+ #[derive(Deserialize, Debug)]
+ #[serde(rename_all = "kebab-case")]
+ struct ComplexInner {
+ another_multipart_name: String,
+ }
+
+ temp_env::with_vars(
+ vec![
+ ("PREFIX__SINGLE", Some("test")),
+ ("PREFIX__PLAIN__VAL", Some("simple")),
+ ("PREFIX__VALUE_WITH_MULTIPART_NAME", Some("value1")),
+ (
+ "PREFIX__INNER_CONFIG__ANOTHER_MULTIPART_NAME",
+ Some("value2"),
+ ),
+ ],
+ || {
+ let environment = Environment::default()
+ .prefix("PREFIX")
+ .convert_case(Case::Kebab)
+ .separator("__");
+
+ let config = Config::builder().add_source(environment).build().unwrap();
+
+ println!("{:#?}", config);
+
+ let config: TestConfig = config.try_deserialize().unwrap();
+
+ assert_eq!(config.single, "test");
+ assert_eq!(config.plain.val, "simple");
+ assert_eq!(config.value_with_multipart_name, "value1");
+ assert_eq!(config.inner_config.another_multipart_name, "value2");
+ },
+ )
+}
+
+#[test]
fn test_parse_string() {
// using a struct in an enum here to make serde use `deserialize_any`
#[derive(Deserialize, Debug)]