Skip to content

Commit

Permalink
Add test cases for stringifing error types
Browse files Browse the repository at this point in the history
Add test cases for `Error::Serde` and `Error::Der`.
  • Loading branch information
nick-mobilecoin committed Sep 21, 2023
1 parent 399d323 commit 900cb1e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions verifier/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,26 @@ impl From<TcbError> 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::<serde_json::Value>(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));
}
}

0 comments on commit 900cb1e

Please sign in to comment.