Skip to content

Commit f4065bb

Browse files
committed
test: body add failed validator
1 parent b657e6a commit f4065bb

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

src/request/validator_test.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,32 @@ paths:
145145

146146
let openapi: OpenAPI = OpenAPI::yaml(content).expect("Failed to parse OpenAPI content");
147147

148-
let data = request::axum::RequestData {
149-
path: "/example".to_string(),
150-
inner: axum::http::Request::builder()
151-
.method("POST")
152-
.uri("/example")
153-
.body(axum::body::Body::from(
154-
r#"{"uuid": "00000000-0000-0000-0000-000000000000"}"#,
155-
))
156-
.unwrap(),
157-
body: Some(Bytes::from(
158-
r#"{"uuid": "00000000-0000-0000-0000-000000000000"}"#,
159-
)),
160-
};
148+
fn make_request(value: &str) -> request::axum::RequestData {
149+
request::axum::RequestData {
150+
path: "/example".to_string(),
151+
inner: axum::http::Request::builder()
152+
.method("POST")
153+
.uri("/example")
154+
.body(axum::body::Body::from(format!(
155+
"{{\"uuid\":\"{}\"}}",
156+
value
157+
)))
158+
.unwrap(),
159+
body: Some(Bytes::from(format!("{{\"uuid\":\"{}\"}}", value))),
160+
}
161+
}
161162

162163
assert!(
163-
openapi.validator(data).is_ok(),
164+
openapi
165+
.validator(make_request("00000000-0000-0000-0000-000000000000"))
166+
.is_ok(),
167+
"Valid body should pass validation"
168+
);
169+
170+
assert!(
171+
!openapi
172+
.validator(make_request("00000000-0000-0000-0000-xxxx"))
173+
.is_ok(),
164174
"Valid body should pass validation"
165175
);
166176
}

0 commit comments

Comments
 (0)