Add coverage converting impl error to jsonreply#936
Add coverage converting impl error to jsonreply#936arminsabouri merged 1 commit intopayjoin:masterfrom
Conversation
Pull Request Test Coverage Report for Build 16784953330Details
💛 - Coveralls |
e75fa8f to
6f3bf4f
Compare
benalleng
left a comment
There was a problem hiding this comment.
uTACK Always nice to see some coverage expansion!
| assert_eq!(reply.error_code, ErrorCode::Unavailable); | ||
| assert_eq!(reply.message, "Receiver error"); |
There was a problem hiding this comment.
Any value in maybe comparing against a dummy JsonReply struct instead of each field?
There was a problem hiding this comment.
IMO yes because there's also the extra field
perhaps my suggestion of adding
struct AlwaysPanics {};
impl fmt::Display for AlwaysPanics {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
panic!("internal error should never display when converting to JsonReply");
}
}
impl fmt::Debug for AlwaysPanics {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
panic!("internal error should never debug when converting to JsonReply");
}
}
impl Error for AlwaysPanics {
fn source(&self) -> Option<&(dyn Error + 'static)> {
panic!("internal error should never be examined when converting to JsonReply");
}
}would be better than asserting about the fields in this case?
There was a problem hiding this comment.
Ben's suggestion of comparing against a struct seems like a nice middleground between low boilerplate and ensuring all fields are accounted for:
| assert_eq!(reply.error_code, ErrorCode::Unavailable); | |
| assert_eq!(reply.message, "Receiver error"); | |
| let expected = JsonReply { error_code: ErrorCode::Unavailable, message: "Receiver error", extra: serde_json::Map::new() }; | |
| assert_eq!(reply, expected); |
Maybe to_json() should also be asserted since that's the actual value that would get transmitted to the sender?
There was a problem hiding this comment.
hmm, i think i feel a bit more strongly after sleeping on it, because it's not really JsonReply's fields we want to ensure will not have any regressions in the future, rather this is about the conversion from ReplyableError::Implementation(internal) to JsonReplyaccurate to me
nothingmuch
left a comment
There was a problem hiding this comment.
utACK, this seems sufficient, my suggestion replying to Ben is arguably more comprehensive/future proof (e.g. in case JsonReply ever gets new fields or something) but it's also more boilerplate, so i'm not married to it
Merging this now. I will leave the ticket open so we can revisit these suggestions |
Related ticket: #932
cc @benalleng as this relates to quality assurance and test coverage