Skip to content

Commit

Permalink
h3i: implement PartialEq<StatusCode> for EnrichedHeaders
Browse files Browse the repository at this point in the history
This makes it easier to write test fixtures since you don't need
manually unwrap the Option<Result> from status_code().
  • Loading branch information
evanrittenhouse committed Nov 17, 2024
1 parent 57bdafd commit c80d478
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion h3i/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ impl From<Vec<Header>> for EnrichedHeaders {
}
}

impl PartialEq<StatusCode> for EnrichedHeaders {
fn eq(&self, other: &StatusCode) -> bool {
self.status_code()
.map(|status| status.ok() == Some(*other))
.unwrap_or(false)
}
}

impl TryFrom<QFrame> for EnrichedHeaders {
type Error = BoxError;

Expand Down Expand Up @@ -446,7 +454,14 @@ mod tests {
let enriched = H3iFrame::Headers(header_frame.into())
.to_enriched_headers()
.unwrap();

assert!(enriched.status_code().is_none());
}

#[test]
fn test_status_code_interaction() {
let header_frame =
EnrichedHeaders::from(vec![Header::new(b":status", b"200")]);

assert_eq!(header_frame, StatusCode::OK);
}
}

0 comments on commit c80d478

Please sign in to comment.