Skip to content

Commit

Permalink
test(config): Ensure CLI overrides work
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Apr 8, 2021
1 parent 29fafd1 commit 68c0a0d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typed-arena = "2.0.1"
assert_fs = "1.0"
predicates = "1.0"
criterion = "0.3"
maplit = "1.0"

[profile.dev]
panic = "abort"
Expand Down
55 changes: 54 additions & 1 deletion src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ impl<'s> ConfigEngine<'s> {

let mut types = Default::default();
std::mem::swap(&mut types, &mut config.type_);

let mut types = types
.into_iter()
.map(|(type_, type_engine)| {
Expand Down Expand Up @@ -338,3 +337,57 @@ impl<'t, 'd> Default for Policy<'t, 'd> {
}
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_load_config_applies_overrides() {
let storage = ConfigStorage::new();
let mut engine = ConfigEngine::new(&storage);
engine.set_isolated(true);

let type_name = kstring::KString::from_static("toml");

let config = crate::config::Config {
default: crate::config::EngineConfig {
binary: Some(true),
check_filename: Some(true),
..Default::default()
},
type_: maplit::hashmap! {
type_name.clone() => crate::config::TypeEngineConfig {
engine: crate::config::EngineConfig {
check_filename: Some(false),
check_file: Some(true),
..Default::default()
},
..Default::default()
},
},
overrides: crate::config::EngineConfig {
binary: Some(false),
check_file: Some(false),
..Default::default()
},
..Default::default()
};
engine.set_overrides(config);

let cwd = std::path::Path::new(".");
let loaded = engine.load_config(&cwd).unwrap();
assert_eq!(loaded.default.binary, Some(false));
assert_eq!(loaded.default.check_filename, Some(true));
assert_eq!(loaded.default.check_file, Some(false));
assert_eq!(loaded.type_[type_name.as_str()].engine.binary, Some(false));
assert_eq!(
loaded.type_[type_name.as_str()].engine.check_filename,
Some(false)
);
assert_eq!(
loaded.type_[type_name.as_str()].engine.check_file,
Some(false)
);
}
}

0 comments on commit 68c0a0d

Please sign in to comment.