From 73363718c3b3836ffef412accf302d249fdd89d0 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Sun, 20 Jul 2025 16:05:34 -0500 Subject: [PATCH] Add test for skipping unavailable conf files Missing config files aren't an error. Make sure there isn't some kind of early return logic that emits broken data. --- src/config.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/config.rs b/src/config.rs index 85b78ac..1afdf26 100644 --- a/src/config.rs +++ b/src/config.rs @@ -310,4 +310,30 @@ mod tests { assert_eq!(load_result, expected); Ok(()) } + + // Ensure that trying to load files that don't exist simply get skipped over + // instead of causing a short-circuit exit or other bogus output. + #[test] + fn test_get_config_many_missing_files() -> Result<()> { + let search_paths = [ + "./test_data/not_real_1.toml", + "./test_data/not_real_2.toml", + "./test_data/not_real_3.toml", + "./test_data/not_real_4.toml", + "./test_data/not_real_5.toml", + "./test_data/sample_config.toml", + "./test_data/not_real_6.toml", + ].into_iter().map(PathBuf::from); + let load_result = get_config("/home/robert/projects/gt-tool", search_paths)?; + let expected = PartialConfig { + project_path: Some(String::from("/home/robert/projects/gt-tool")), + owner: Some(String::from("robert")), + repo: Some(String::from("gt-tool")), + gitea_url: Some(String::from("http://localhost:3000")), + token: Some(String::from("fake-token")), + }; + + assert_eq!(load_result, expected); + Ok(()) + } }