entrenar/storage/cloud/
azure.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct AzureConfig {
8 pub account: String,
10 pub container: String,
12 pub prefix: String,
14 pub connection_string: Option<String>,
16}
17
18impl AzureConfig {
19 pub fn new(account: &str, container: &str) -> Self {
21 Self {
22 account: account.to_string(),
23 container: container.to_string(),
24 prefix: String::new(),
25 connection_string: None,
26 }
27 }
28
29 pub fn with_prefix(mut self, prefix: &str) -> Self {
31 self.prefix = prefix.to_string();
32 self
33 }
34
35 pub fn with_connection_string(mut self, conn_str: &str) -> Self {
37 self.connection_string = Some(conn_str.to_string());
38 self
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_azure_config_new() {
48 let config = AzureConfig::new("myaccount", "mycontainer");
49 assert_eq!(config.account, "myaccount");
50 assert_eq!(config.container, "mycontainer");
51 }
52
53 #[test]
54 fn test_azure_config_with_prefix() {
55 let config = AzureConfig::new("account", "container").with_prefix("models/");
56 assert_eq!(config.prefix, "models/");
57 }
58
59 #[test]
60 fn test_azure_config_with_connection_string() {
61 let config = AzureConfig::new("account", "container")
62 .with_connection_string("DefaultEndpointsProtocol=https;...");
63 assert!(config.connection_string.is_some());
64 }
65
66 #[test]
67 fn test_azure_config_serde() {
68 let config = AzureConfig::new("account", "container")
69 .with_prefix("models/")
70 .with_connection_string("conn");
71
72 let json = serde_json::to_string(&config).expect("JSON serialization should succeed");
73 let parsed: AzureConfig =
74 serde_json::from_str(&json).expect("JSON deserialization should succeed");
75
76 assert_eq!(config.account, parsed.account);
77 assert_eq!(config.container, parsed.container);
78 assert_eq!(config.prefix, parsed.prefix);
79 }
80}