Skip to content

Commit

Permalink
Test parse_url_opts for HTTP (#5310) (#5316)
Browse files Browse the repository at this point in the history
* Test parse_url_opts for HTTP (#5310)

* Format
  • Loading branch information
tustvold committed Jan 20, 2024
1 parent 639e81e commit b03613e
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion object_store/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl ObjectStoreScheme {
macro_rules! builder_opts {
($builder:ty, $url:expr, $options:expr) => {{
let builder = $options.into_iter().fold(
<$builder>::new().with_url($url.as_str()),
<$builder>::new().with_url($url.to_string()),
|builder, (key, value)| match key.as_ref().parse() {
Ok(k) => builder.with_config(k, value),
Err(_) => builder,
Expand Down Expand Up @@ -164,6 +164,7 @@ where
}
#[cfg(feature = "http")]
ObjectStoreScheme::Http => {
let url = &url[..url::Position::BeforePath];
builder_opts!(crate::http::HttpBuilder, url, _options)
}
#[cfg(not(all(feature = "aws", feature = "azure", feature = "gcp", feature = "http")))]
Expand Down Expand Up @@ -305,4 +306,28 @@ mod tests {
let (_, path) = parse_url(&url).unwrap();
assert_eq!(path.as_ref(), "my file with spaces");
}

#[tokio::test]
#[cfg(feature = "http")]
async fn test_url_http() {
use crate::client::mock_server::MockServer;
use hyper::{header::USER_AGENT, Body, Response};

let server = MockServer::new();

server.push_fn(|r| {
assert_eq!(r.uri().path(), "/foo/bar");
assert_eq!(r.headers().get(USER_AGENT).unwrap(), "test_url");
Response::new(Body::empty())
});

let test = format!("{}/foo/bar", server.url());
let opts = [("user_agent", "test_url"), ("allow_http", "true")];
let url = test.parse().unwrap();
let (store, path) = parse_url_opts(&url, opts).unwrap();
assert_eq!(path.as_ref(), "foo/bar");
store.get(&path).await.unwrap();

server.shutdown().await;
}
}

0 comments on commit b03613e

Please sign in to comment.