@@ -73,38 +73,28 @@ mod destructure_url_in_place {
73
73
) ;
74
74
}
75
75
76
- #[ test]
77
- fn protocol_and_host_without_url_constructs_url_first ( ) {
78
- let mut ctx = Context {
79
- protocol : Some ( "https" . into ( ) ) ,
80
- host : Some ( "github.com" . into ( ) ) ,
81
- ..Default :: default ( )
82
- } ;
83
- ctx. destructure_url_in_place ( false ) . expect ( "should work with protocol and host" ) ;
84
-
85
- // URL should be constructed from protocol and host
86
- assert_eq ! ( ctx. url. as_deref( ) . map( |b| & * * b) , Some ( "https://github.com" . as_bytes( ) ) ) ;
87
- // Original fields should be preserved
88
- assert_eq ! ( ctx. protocol. as_deref( ) , Some ( "https" ) ) ;
89
- assert_eq ! ( ctx. host. as_deref( ) , Some ( "github.com" ) ) ;
90
- }
91
-
92
76
#[ test]
93
77
fn protocol_and_host_with_path_without_url_constructs_full_url ( ) {
94
78
let mut ctx = Context {
95
79
protocol : Some ( "https" . into ( ) ) ,
96
80
host : Some ( "github.com" . into ( ) ) ,
97
81
path : Some ( "org/repo" . into ( ) ) ,
82
+ username : Some ( "user" . into ( ) ) ,
83
+ password : Some ( "pass-to-be-ignored" . into ( ) ) ,
98
84
..Default :: default ( )
99
85
} ;
100
- ctx. destructure_url_in_place ( false ) . expect ( "should work with protocol, host and path" ) ;
101
-
102
- // URL should be constructed from all provided fields
103
- assert_eq ! ( ctx. url. as_deref( ) . map( |b| & * * b) , Some ( "https://github.com/org/repo" . as_bytes( ) ) ) ;
86
+ ctx. destructure_url_in_place ( false )
87
+ . expect ( "should work with protocol, host and path" ) ;
88
+
89
+ assert_eq ! (
90
+ ctx. url. unwrap( ) ,
91
+ "https://[email protected] /org/repo" ,
92
+ "URL should be constructed from all provided fields, except password"
93
+ ) ;
104
94
// Original fields should be preserved
105
95
assert_eq ! ( ctx. protocol. as_deref( ) , Some ( "https" ) ) ;
106
96
assert_eq ! ( ctx. host. as_deref( ) , Some ( "github.com" ) ) ;
107
- assert_eq ! ( ctx. path. as_deref ( ) . map ( |b| & * * b ) , Some ( "org/repo" . as_bytes ( ) ) ) ;
97
+ assert_eq ! ( ctx. path. unwrap ( ) , "org/repo" ) ;
108
98
}
109
99
110
100
#[ test]
@@ -113,7 +103,10 @@ mod destructure_url_in_place {
113
103
host : Some ( "github.com" . into ( ) ) ,
114
104
..Default :: default ( )
115
105
} ;
116
- assert ! ( ctx_no_protocol. destructure_url_in_place( false ) . is_err( ) ) ;
106
+ assert_eq ! (
107
+ ctx_no_protocol. destructure_url_in_place( false ) . unwrap_err( ) . to_string( ) ,
108
+ "Either 'url' field or both 'protocol' and 'host' fields must be provided"
109
+ ) ;
117
110
118
111
let mut ctx_no_host = Context {
119
112
protocol : Some ( "https" . into ( ) ) ,
0 commit comments