From 900cb1e1fc2053a473ccfd9578688550bae00315 Mon Sep 17 00:00:00 2001 From: Nick Santana Date: Fri, 8 Sep 2023 11:49:59 -0700 Subject: [PATCH] Add test cases for stringifing error types Add test cases for `Error::Serde` and `Error::Der`. --- verifier/src/error.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/verifier/src/error.rs b/verifier/src/error.rs index 35193cf..8220cbc 100644 --- a/verifier/src/error.rs +++ b/verifier/src/error.rs @@ -60,3 +60,26 @@ impl From for Error { Error::Quote3TcbInfo(e) } } + +#[cfg(test)] +mod test { + use super::*; + use assert_matches::assert_matches; + + #[test] + fn serde_error_to_string() { + let bad_json = "not json"; + let e = serde_json::from_str::(bad_json).unwrap_err(); + let serde_error_message = e.to_string(); + let err = Error::from(e); + assert_matches!(err, Error::Serde(message) if message.contains(&serde_error_message)); + } + + #[test] + fn der_error_to_string() { + let e = der::Error::incomplete(1u8.into()); + let der_error_message = e.to_string(); + let err = Error::from(e); + assert_matches!(err, Error::Der(message) if message.contains(&der_error_message)); + } +}