diff --git a/src/config.rs b/src/config.rs index d40096c..08a184f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -71,6 +71,10 @@ struct WholeFile { project_overrides: Vec, } +fn load_from_file(path: &str) -> Result { + todo!(); +} + fn read_conf_str(text: &str) -> Result { let mut whole = WholeFile::default(); @@ -242,4 +246,30 @@ mod tests { let conf = read_conf_str(fx_sample_cfg); assert!(conf.is_err()); } + + #[test] + // File exists and has valid configuration. + fn load_from_file_ok() -> Result<()> { + let conf = load_from_file("test_data/sample_config.toml")?; + assert_eq!(conf, gen_expected_struct()); + Ok(()) + } + + #[test] + // File does not exist. + fn load_from_file_missing() -> Result<()> { + let res = load_from_file("test_data/doesnt_exist.toml"); + let err = res.unwrap_err(); + assert_eq!(err, todo!("Need a new config::Error variant to indicate a missing config file")); + Ok(()) + } + + #[test] + // File exists but has garbage inside. + // TODO: This bumps against the same semantic issue as the todo note on + // the 'read_config_string_empty' test + fn load_from_file_bad() { + let res = load_from_file("test_data/missing_all_table.toml"); + assert!(res.is_err()); + } } diff --git a/test_data/missing_all_table.toml b/test_data/missing_all_table.toml new file mode 100644 index 0000000..c89da34 --- /dev/null +++ b/test_data/missing_all_table.toml @@ -0,0 +1,5 @@ +# There must be an "[all]" table or the loader will reject the config file. + +["/some/other/path"] +gitea_url = "fake-url" +