Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions axum-extra/src/protobuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ mod tests {
use super::*;
use crate::test_helpers::*;
use axum::{routing::post, Router};
use http::header::CONTENT_TYPE;
use http::StatusCode;

#[tokio::test]
async fn decode_body() {
Expand All @@ -182,9 +184,11 @@ mod tests {
let client = TestClient::new(app);
let res = client.post("/").body(input.encode_to_vec()).await;

let status = res.status();
let body = res.text().await;

assert_eq!(body, "bar");
assert_eq!(status, StatusCode::OK);
assert_eq!(body, input.foo);
}

#[tokio::test]
Expand All @@ -211,6 +215,7 @@ mod tests {
let res = client.post("/").body(input.encode_to_vec()).await;

assert_eq!(res.status(), StatusCode::UNPROCESSABLE_ENTITY);
assert!(res.text().await.starts_with("Failed to decode the body"));
}

#[tokio::test]
Expand Down Expand Up @@ -243,15 +248,20 @@ mod tests {
let client = TestClient::new(app);
let res = client.post("/").body(input.encode_to_vec()).await;

let content_type_header_value = res
.headers()
.get(CONTENT_TYPE)
.expect("missing expected header");

assert_eq!(
res.headers()["content-type"],
content_type_header_value,
mime::APPLICATION_OCTET_STREAM.as_ref()
);

let body = res.bytes().await;

let output = Output::decode(body).unwrap();

assert_eq!(output.result, "bar");
assert_eq!(output.result, input.foo);
}
}
Loading