gitflow_core/
auth_checker.rs1pub trait AuthChecker: Send + Sync {
19 fn is_authenticated(&self) -> bool;
25
26 fn check_status(&self) -> AuthCheckResult;
32}
33
34#[derive(Debug, Clone)]
38pub struct AuthCheckResult {
39 pub authenticated: bool,
41 pub user: Option<String>,
43 pub reason: Option<String>,
45 pub hint: Option<String>,
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_should_create_authenticated_result() {
55 let result = AuthCheckResult {
56 authenticated: true,
57 user: Some("testuser".to_string()),
58 reason: None,
59 hint: None,
60 };
61 assert!(result.authenticated);
62 assert_eq!(result.user, Some("testuser".to_string()));
63 }
64
65 #[test]
66 fn test_should_create_not_authenticated_result() {
67 let result = AuthCheckResult {
68 authenticated: false,
69 user: None,
70 reason: Some("Not logged in".to_string()),
71 hint: Some("Run `gc auth login`".to_string()),
72 };
73 assert!(!result.authenticated);
74 assert!(result.reason.is_some());
75 assert!(result.hint.is_some());
76 }
77
78 #[test]
79 fn test_auth_checker_trait_is_object_safe() {
80 fn _takes_checker(_checker: &dyn AuthChecker) {}
82 }
83}