Skip to content

Commit

Permalink
Add tests for detail serde
Browse files Browse the repository at this point in the history
  • Loading branch information
petkovicdanilo committed Sep 8, 2021
1 parent fa9f59a commit abdffd5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/distribution/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,43 @@ mod tests {
fn error_info_failure() {
assert!(ErrorInfoBuilder::default().build().is_err());
}

#[test]
fn error_info_serialize_success() -> Result<()> {
let error_info = ErrorInfoBuilder::default()
.code(ErrorCode::Unauthorized)
.detail(String::from("{ \"key\": \"value\" }"))
.build()?;

assert!(serde_json::to_string(&error_info).is_ok());
Ok(())
}

#[test]
fn error_info_serialize_failure() -> Result<()> {
let error_info = ErrorInfoBuilder::default()
.code(ErrorCode::Unauthorized)
.detail(String::from("abcd"))
.build()?;

assert!(serde_json::to_string(&error_info).is_err());
Ok(())
}

#[test]
fn error_info_deserialize_success() -> Result<()> {
let error_info_str = r#"
{
"code": "MANIFEST_UNKNOWN",
"message": "manifest tagged by \"lates\" is not found",
"detail": {
"Tag": "lates"
}
}"#;

let error_info: ErrorInfo = serde_json::from_str(&error_info_str)?;
assert_eq!(error_info.detail().as_ref().unwrap(), "{\"Tag\":\"lates\"}");

Ok(())
}
}

0 comments on commit abdffd5

Please sign in to comment.