File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -107,3 +107,41 @@ impl Client {
107107 Ok ( res. parse ( ) ?)
108108 }
109109}
110+
111+ #[ cfg( test) ]
112+ mod test_auth {
113+ use super :: * ;
114+
115+ #[ test]
116+ fn test_auth_user_pass_get_user_pass ( ) {
117+ let auth = Auth :: UserPass ( "user" . to_string ( ) , "pass" . to_string ( ) ) ;
118+ let result = auth. get_user_pass ( ) . expect ( "failed to get user pass" ) ;
119+
120+ assert_eq ! ( result, ( Some ( "user" . to_string( ) ) , Some ( "pass" . to_string( ) ) ) ) ;
121+ }
122+
123+ #[ test]
124+ fn test_auth_none_get_user_pass ( ) {
125+ let auth = Auth :: None ;
126+ let result = auth. get_user_pass ( ) . expect ( "failed to get user pass" ) ;
127+
128+ assert_eq ! ( result, ( None , None ) ) ;
129+ }
130+
131+ #[ test]
132+ fn test_auth_cookie_file_get_user_pass ( ) {
133+ let temp_dir = std:: env:: temp_dir ( ) ;
134+ let cookie_path = temp_dir. join ( "test_auth_cookie" ) ;
135+ std:: fs:: write ( & cookie_path, "testuser:testpass" ) . expect ( "failed to write cookie" ) ;
136+
137+ let auth = Auth :: CookieFile ( cookie_path. clone ( ) ) ;
138+ let result = auth. get_user_pass ( ) . expect ( "failed to get user pass" ) ;
139+
140+ assert_eq ! (
141+ result,
142+ ( Some ( "testuser" . to_string( ) ) , Some ( "testpass" . to_string( ) ) )
143+ ) ;
144+
145+ std:: fs:: remove_file ( cookie_path) . ok ( ) ;
146+ }
147+ }
You can’t perform that action at this time.
0 commit comments