Skip to content

Commit

Permalink
chore(sinks): fix endpoint strip for aws region (vectordotdev#3070)
Browse files Browse the repository at this point in the history
* chore(sinks): fix endpoint strip for aws region

Signed-off-by: Kirill Fomichev <[email protected]>

* add test

Signed-off-by: Kirill Fomichev <[email protected]>

* add yet one test

Signed-off-by: Kirill Fomichev <[email protected]>

* Github actions is buggy

Signed-off-by: Ana Hobden <[email protected]>

Co-authored-by: Ana Hobden <[email protected]>
Signed-off-by: Brian Menges <[email protected]>
  • Loading branch information
2 people authored and Brian Menges committed Dec 9, 2020
1 parent 6dfed82 commit d0668d2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn strip_endpoint(uri: &Uri) -> String {
let pq_len = uri
.path_and_query()
.map(|pq| pq.as_str().len())
.unwrap_or(1);
.unwrap_or(0);
let endpoint = uri.to_string();
endpoint[..endpoint.len() - pq_len].to_string()
}
Expand Down Expand Up @@ -204,6 +204,24 @@ mod tests {
);
}

#[test]
fn region_from_endpoint_without_scheme() {
assert_eq!(
region_from_endpoint("ams3.digitaloceanspaces.com").unwrap(),
Region::Custom {
name: "us-east-1".into(),
endpoint: "ams3.digitaloceanspaces.com".into()
}
);
assert_eq!(
region_from_endpoint("https://ams3.digitaloceanspaces.com/").unwrap(),
Region::Custom {
name: "us-east-1".into(),
endpoint: "https://ams3.digitaloceanspaces.com".into()
}
);
}

#[test]
fn region_from_endpoint_strips_path_query() {
assert_eq!(
Expand Down

0 comments on commit d0668d2

Please sign in to comment.