From 602dcba892587c95b64a64f0aabfcdc9f26f1dac Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 17 Jan 2025 14:31:01 -0500 Subject: [PATCH] Change test case to match error via types, not strings Minor followup to the previous change; part of the idea of having the error types here is so we can *also* dig through the `SkopeoSpawnError` and precisely match against the `std::io::ErrorKind::NotFound`, and not rely on its stringified form. This is what we'd expect other callers to do. This also avoids a double-match. Signed-off-by: Colin Walters --- src/imageproxy.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/imageproxy.rs b/src/imageproxy.rs index 10cda74..fb61948 100644 --- a/src/imageproxy.rs +++ b/src/imageproxy.rs @@ -701,11 +701,16 @@ mod tests { }; config.skopeo_cmd = Some(Command::new("no-skopeo")); - let res = ImageProxy::new_with_config(config).await; - assert!(matches!(res, Err(Error::SkopeoSpawnError(_)))); - assert_eq!( - res.err().unwrap().to_string(), - "skopeo spawn error: No such file or directory (os error 2)" - ); + match ImageProxy::new_with_config(config).await { + Ok(_) => panic!("Expected an error"), + Err(ref e @ Error::SkopeoSpawnError(ref inner)) => { + assert_eq!(inner.kind(), std::io::ErrorKind::NotFound); + // Just to double check + assert!(e + .to_string() + .contains("skopeo spawn error: No such file or directory")); + } + Err(e) => panic!("Unexpected error {e}"), + } } }