Skip to main content

mangofetch_plugin_sdk/
host.rs

1use std::path::PathBuf;
2
3pub trait PluginHost: Send + Sync {
4    fn emit_event(&self, name: &str, payload: serde_json::Value) -> anyhow::Result<()>;
5    fn show_toast(&self, toast_type: &str, message: &str) -> anyhow::Result<()>;
6    fn plugin_data_dir(&self, plugin_id: &str) -> PathBuf;
7    fn plugin_frontend_dir(&self, plugin_id: &str) -> PathBuf;
8    fn get_settings(&self, plugin_id: &str) -> serde_json::Value;
9    fn save_settings(&self, plugin_id: &str, settings: serde_json::Value) -> anyhow::Result<()>;
10    fn proxy_config(&self) -> Option<ProxyConfig>;
11    fn tool_path(&self, tool: &str) -> Option<PathBuf>;
12    fn default_output_dir(&self) -> PathBuf;
13}
14
15#[derive(Debug, Clone)]
16pub struct ProxyConfig {
17    pub proxy_type: String,
18    pub host: String,
19    pub port: u16,
20    pub username: Option<String>,
21    pub password: Option<String>,
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn test_proxy_config_creation() {
30        let config = ProxyConfig {
31            proxy_type: "http".to_string(),
32            host: "127.0.0.1".to_string(),
33            port: 8080,
34            username: None,
35            password: None,
36        };
37
38        assert_eq!(config.proxy_type, "http");
39        assert_eq!(config.host, "127.0.0.1");
40        assert_eq!(config.port, 8080);
41        assert_eq!(config.username, None);
42        assert_eq!(config.password, None);
43    }
44
45    #[test]
46    fn test_proxy_config_with_auth() {
47        let config = ProxyConfig {
48            proxy_type: "socks5".to_string(),
49            host: "proxy.example.com".to_string(),
50            port: 1080,
51            username: Some("user123".to_string()),
52            password: Some("secret_pass".to_string()),
53        };
54
55        assert_eq!(config.proxy_type, "socks5");
56        assert_eq!(config.host, "proxy.example.com");
57        assert_eq!(config.port, 1080);
58        assert_eq!(config.username.as_deref(), Some("user123"));
59        assert_eq!(config.password.as_deref(), Some("secret_pass"));
60    }
61
62    #[test]
63    fn test_proxy_config_clone() {
64        let config = ProxyConfig {
65            proxy_type: "http".to_string(),
66            host: "localhost".to_string(),
67            port: 3128,
68            username: Some("testuser".to_string()),
69            password: None,
70        };
71
72        let cloned = config.clone();
73
74        assert_eq!(config.proxy_type, cloned.proxy_type);
75        assert_eq!(config.host, cloned.host);
76        assert_eq!(config.port, cloned.port);
77        assert_eq!(config.username, cloned.username);
78        assert_eq!(config.password, cloned.password);
79    }
80
81    #[test]
82    fn test_proxy_config_debug() {
83        let config = ProxyConfig {
84            proxy_type: "https".to_string(),
85            host: "secure.proxy.org".to_string(),
86            port: 443,
87            username: None,
88            password: None,
89        };
90
91        let debug_str = format!("{:?}", config);
92        assert!(debug_str.contains("ProxyConfig"));
93        assert!(debug_str.contains("proxy_type: \"https\""));
94        assert!(debug_str.contains("host: \"secure.proxy.org\""));
95        assert!(debug_str.contains("port: 443"));
96    }
97}