@@ -290,14 +290,13 @@ pub struct Connection {
290
290
impl Connection {
291
291
/// Creates a new instance of a [Connection].
292
292
///
293
- /// If the passed [url::Url] does not have a trailing forward slash, a new
294
- /// url is constructed from the passed url, with a trailing slash.
293
+ /// If the passed [url::Url] path does not have a trailing forward slash, a trailing
294
+ /// forward slash will be appended
295
295
pub fn new ( url : Url ) -> Self {
296
- let url = if !url. path ( ) . ends_with ( '/' ) {
297
- Url :: parse ( format ! ( "{}/" , url. as_str( ) ) . as_ref ( ) ) . unwrap ( )
298
- } else {
299
- url
300
- } ;
296
+ let mut url = url;
297
+ if !url. path ( ) . ends_with ( '/' ) {
298
+ url. set_path ( & format ! ( "{}/" , url. path( ) ) ) ;
299
+ }
301
300
302
301
Self { url }
303
302
}
@@ -630,7 +629,7 @@ pub mod tests {
630
629
}
631
630
632
631
#[ test]
633
- fn can_parse_cloud_id ( ) {
632
+ fn can_parse_cloud_id_with_kibana_uuid ( ) {
634
633
let base64 = base64:: encode ( "cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4" ) ;
635
634
let cloud_id = format ! ( "my_cluster:{}" , base64) ;
636
635
let result = CloudId :: parse ( & cloud_id) ;
@@ -643,6 +642,35 @@ pub mod tests {
643
642
) ;
644
643
}
645
644
645
+ #[ test]
646
+ fn can_parse_cloud_id_without_kibana_uuid ( ) {
647
+ let base64 = base64:: encode ( "cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$" ) ;
648
+ let cloud_id = format ! ( "my_cluster:{}" , base64) ;
649
+ let result = CloudId :: parse ( & cloud_id) ;
650
+ assert ! ( result. is_ok( ) ) ;
651
+ let cloud = result. unwrap ( ) ;
652
+ assert_eq ! ( "my_cluster" , cloud. name) ;
653
+ assert_eq ! (
654
+ Url :: parse( "https://3dadf823f05388497ea684236d918a1a.cloud-endpoint.example" ) . unwrap( ) ,
655
+ cloud. url
656
+ ) ;
657
+ }
658
+
659
+ #[ test]
660
+ fn can_parse_cloud_id_with_different_port ( ) {
661
+ let base64 = base64:: encode ( "cloud-endpoint.example:4463$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4" ) ;
662
+ let cloud_id = format ! ( "my_cluster:{}" , base64) ;
663
+ let result = CloudId :: parse ( & cloud_id) ;
664
+ assert ! ( result. is_ok( ) ) ;
665
+ let cloud = result. unwrap ( ) ;
666
+ assert_eq ! ( "my_cluster" , cloud. name) ;
667
+ assert_eq ! (
668
+ Url :: parse( "https://3dadf823f05388497ea684236d918a1a.cloud-endpoint.example:4463" )
669
+ . unwrap( ) ,
670
+ cloud. url
671
+ ) ;
672
+ }
673
+
646
674
#[ test]
647
675
fn cloud_id_must_contain_colon ( ) {
648
676
let base64 = base64:: encode ( "cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4" ) ;
@@ -659,7 +687,7 @@ pub mod tests {
659
687
}
660
688
661
689
#[ test]
662
- fn cloud_id_first_cannot_be_empty ( ) {
690
+ fn cloud_id_first_part_cannot_be_empty ( ) {
663
691
let base64 = base64:: encode ( "cloud-endpoint.example$3dadf823f05388497ea684236d918a1a$3f26e1609cf54a0f80137a80de560da4" ) ;
664
692
let cloud_id = format ! ( ":{}" , base64) ;
665
693
let cloud = CloudId :: parse ( & cloud_id) ;
0 commit comments