From a22567c188134aa87d6d5d8efd6ba784894f032d Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 7 Apr 2021 21:14:57 -0500 Subject: [PATCH] test(config): Ensure types are validated --- src/policy.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/policy.rs b/src/policy.rs index 5faddf9..b957706 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -342,6 +342,8 @@ impl<'t, 'd> Default for Policy<'t, 'd> { mod test { use super::*; + const NEVER_EXIST_TYPE: &str = "this-type-should-never-exist-but-i-hate-you-if-it-does"; + #[test] fn test_load_config_applies_overrides() { let storage = ConfigStorage::new(); @@ -390,4 +392,27 @@ mod test { Some(false) ); } + + #[test] + fn test_init_fails_on_unknown_type() { + let storage = ConfigStorage::new(); + let mut engine = ConfigEngine::new(&storage); + engine.set_isolated(true); + + let type_name = kstring::KString::from_static(NEVER_EXIST_TYPE); + + let config = crate::config::Config { + type_: maplit::hashmap! { + type_name.clone() => crate::config::TypeEngineConfig { + ..Default::default() + }, + }, + ..Default::default() + }; + engine.set_overrides(config); + + let cwd = std::path::Path::new("."); + let result = engine.init_dir(&cwd); + assert!(result.is_err()); + } }