Skip to content

Commit e901b60

Browse files
committed
add unit tests
1 parent fd22670 commit e901b60

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/client.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)