Skip to content

Commit

Permalink
tests: inline trivial helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Dec 20, 2024
1 parent 515822c commit a38dfae
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,28 +221,28 @@ mod tests {

#[tokio::test]
async fn connects_https() {
oneshot(https_or_http_connector(), https_uri())
oneshot(https_or_http_connector(), Scheme::Https)
.await
.unwrap();
}

#[tokio::test]
async fn connects_http() {
oneshot(https_or_http_connector(), http_uri())
oneshot(https_or_http_connector(), Scheme::Http)
.await
.unwrap();
}

#[tokio::test]
async fn connects_https_only() {
oneshot(https_only_connector(), https_uri())
oneshot(https_only_connector(), Scheme::Https)
.await
.unwrap();
}

#[tokio::test]
async fn enforces_https_only() {
let message = oneshot(https_only_connector(), http_uri())
let message = oneshot(https_only_connector(), Scheme::Http)
.await
.unwrap_err()
.to_string();
Expand Down Expand Up @@ -284,16 +284,21 @@ mod tests {
.with_no_client_auth();
}

async fn oneshot<S: Service<Uri>>(mut service: S, req: Uri) -> Result<S::Response, S::Error> {
async fn oneshot<S: Service<Uri>>(
mut service: S,
scheme: Scheme,
) -> Result<S::Response, S::Error> {
poll_fn(|cx| service.poll_ready(cx)).await?;
service.call(req).await
}

fn https_uri() -> Uri {
Uri::from_static("https://google.com")
service
.call(Uri::from_static(match scheme {
Scheme::Https => "https://google.com",
Scheme::Http => "http://google.com",
}))
.await
}

fn http_uri() -> Uri {
Uri::from_static("http://google.com")
enum Scheme {
Https,
Http,
}
}

0 comments on commit a38dfae

Please sign in to comment.