From a08466c834729b49de3e6665a476fc2f87d4fe13 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Wed, 4 Jun 2025 11:52:31 -0500 Subject: [PATCH] Test fix: uploading missing file shouldn't panic There's a check in the create_release_attachment() function to ensure the files exist before attempting to read them. Clearly, it isn't working correctly. I've dropped the `#[should_panic]` annotation and added a better Result unpacking routine. It will report specific messages based on the result. --- src/api/release_attachment.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/api/release_attachment.rs b/src/api/release_attachment.rs index 028cc9c..a7d4987 100644 --- a/src/api/release_attachment.rs +++ b/src/api/release_attachment.rs @@ -74,7 +74,6 @@ mod tests { } #[tokio::test] - #[should_panic] async fn attach_file_missing() { let conf = TestConfig::new(); let release_candidates = @@ -97,6 +96,14 @@ mod tests { vec![String::from("./this-file-doesnt-exist")], ) .await; + let api_err = api_result.expect_err("Received Ok(()) after uploading non-existent file. That's nonsense, the API Function is wrong."); + match api_err { + crate::Error::Placeholder => panic!("Received dummy response from the API function. Finish implementing it, stupid"), + crate::Error::WrappedReqwestErr(error) => panic!("Received a reqwest::Error from the API function: {error}"), + crate::Error::MissingAuthToken => unreachable!("Missing auth token... in a unit test that already panics without the auth token..."), + crate::Error::NoSuchFile => (), // test passes + crate::Error::ApiErrorMessage(api_error) => panic!("Received an error message from the API: {api_error:?}"), + } } struct TestConfig {