Skip to content

Commit fc73951

Browse files
author
Fahad Zubair
committed
Add uri_with_only_path test
1 parent aef9c71 commit fc73951

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

rust-runtime/aws-smithy-http-server/src/layer/alb_health_check.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,19 @@ mod tests {
187187
use tower::{service_fn, ServiceExt};
188188

189189
#[tokio::test]
190-
async fn health_check_matches_path_with_scheme_and_authority() {
191-
let layer = AlbHealthCheckLayer::from_handler("/ping", |_req| async { StatusCode::OK });
190+
async fn health_check_matches_path_when_uri_contains_scheme_authority_and_path() {
191+
let uri: Uri = "https://example.com/ping".parse().unwrap();
192+
ensure_health_check_path_matches(uri, "/ping".to_string()).await;
193+
}
194+
195+
#[tokio::test]
196+
async fn health_check_matches_path_when_uri_contains_only_path() {
197+
let uri: Uri = "/ping".parse().unwrap();
198+
ensure_health_check_path_matches(uri, "/ping".to_string()).await;
199+
}
192200

201+
async fn ensure_health_check_path_matches(uri: Uri, health_check_path: String) {
202+
let layer = AlbHealthCheckLayer::from_handler(health_check_path, |_req| async { StatusCode::OK });
193203
let inner_service = service_fn(|_req| async {
194204
Ok::<_, std::convert::Infallible>(
195205
Response::builder()
@@ -200,10 +210,7 @@ mod tests {
200210
});
201211

202212
let service = layer.layer(inner_service);
203-
204-
let uri: Uri = "https://example.com/ping".parse().unwrap();
205213
let request = Request::builder().uri(uri).body(Body::empty()).unwrap();
206-
207214
let response = service.oneshot(request).await.unwrap();
208215
assert_eq!(response.status(), StatusCode::OK);
209216
}

0 commit comments

Comments
 (0)