Skip to content

Commit

Permalink
config: remove merge() function which is used only in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Dec 3, 2024
1 parent 47341d8 commit b23459f
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,6 @@ impl StackedConfig {
&self.layers
}

/// Creates new merged config.
pub fn merge(&self) -> config::Config {
self.layers
.iter()
.fold(config::Config::builder(), |builder, layer| {
builder.add_source(layer.data.clone())
})
.build()
.expect("loaded configs should be merged without error")
}

/// Looks up value of the specified type `T` from all layers, merges sub
/// fields as needed.
pub fn get<'de, T: Deserialize<'de>>(
Expand Down Expand Up @@ -555,43 +544,26 @@ mod tests {
a.d = ['a.d #1']
"}));

assert_eq!(config.merge().get::<String>("a.b.c").unwrap(), "a.b.c #0");
assert_eq!(config.get::<String>("a.b.c").unwrap(), "a.b.c #0");

assert_eq!(
config.merge().get::<Vec<String>>("a.d").unwrap(),
vec!["a.d #1".to_owned()]
);
assert_eq!(
config.get::<Vec<String>>("a.d").unwrap(),
vec!["a.d #1".to_owned()]
);

// Table "a.b" exists, but key doesn't
assert_matches!(
config.merge().get::<String>("a.b.missing"),
Err(ConfigError::NotFound(name)) if name == "a.b.missing"
);
assert_matches!(
config.get::<String>("a.b.missing"),
Err(ConfigError::NotFound(name)) if name == "a.b.missing"
);

// Node "a.b.c" is not a table
assert_matches!(
config.merge().get::<String>("a.b.c.d"),
Err(ConfigError::NotFound(name)) if name == "a.b.c.d"
);
assert_matches!(
config.get::<String>("a.b.c.d"),
Err(ConfigError::NotFound(name)) if name == "a.b.c.d"
);

// Type error
assert_matches!(
config.merge().get::<String>("a.b"),
Err(ConfigError::Type { key: Some(name), .. }) if name == "a.b"
);
assert_matches!(
config.get::<String>("a.b"),
Err(ConfigError::Type { key: Some(name), .. }) if name == "a.b"
Expand All @@ -609,13 +581,8 @@ mod tests {
a.b = 'a.b #1'
"}));

assert_eq!(config.merge().get::<String>("a.b").unwrap(), "a.b #1");
assert_eq!(config.get::<String>("a.b").unwrap(), "a.b #1");

assert_matches!(
config.merge().get::<String>("a.b.c"),
Err(ConfigError::NotFound(name)) if name == "a.b.c"
);
assert_matches!(
config.get::<String>("a.b.c"),
Err(ConfigError::NotFound(name)) if name == "a.b.c"
Expand All @@ -636,7 +603,6 @@ mod tests {
let expected = parse_to_table(indoc! {"
c = 'a.b.c #1'
"});
assert_eq!(config.merge().get_table("a.b").unwrap(), expected);
assert_eq!(config.get_table("a.b").unwrap(), expected);
}

Expand All @@ -660,7 +626,6 @@ mod tests {
b = 'a.b #0'
c = 'a.c #1'
"});
assert_eq!(config.merge().get_table("a").unwrap(), expected);
assert_eq!(config.get_table("a").unwrap(), expected);
}

Expand All @@ -682,7 +647,6 @@ mod tests {
let expected = parse_to_table(indoc! {"
a.b = 'a.a.b #2'
"});
assert_eq!(config.merge().get_table("a").unwrap(), expected);
assert_eq!(config.get_table("a").unwrap(), expected);
}

Expand All @@ -705,7 +669,6 @@ mod tests {
a.b = 'a.a.b #2'
b = 'a.b #0'
"});
assert_eq!(config.merge().get_table("a").unwrap(), expected);
assert_eq!(config.get_table("a").unwrap(), expected);
}

Expand All @@ -727,7 +690,6 @@ mod tests {
b = 'a.a.b #2'
"});
// a is not under a.a, but it should still shadow lower layers
assert_eq!(config.merge().get_table("a.a").unwrap(), expected);
assert_eq!(config.get_table("a.a").unwrap(), expected);
}
}

0 comments on commit b23459f

Please sign in to comment.