torrust_tracker_deployer_lib/domain/provider/
lxd.rs1use serde::{Deserialize, Serialize};
8
9use crate::domain::ProfileName;
10
11#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
30pub struct LxdConfig {
31 pub profile_name: ProfileName,
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn it_should_store_validated_profile_name_when_created() {
44 let profile_name = ProfileName::new("test-profile").unwrap();
45 let config = LxdConfig {
46 profile_name: profile_name.clone(),
47 };
48 assert_eq!(config.profile_name, profile_name);
49 }
50
51 #[test]
52 fn it_should_serialize_to_json_when_valid_config_exists() {
53 let config = LxdConfig {
54 profile_name: ProfileName::new("torrust-profile").unwrap(),
55 };
56 let json = serde_json::to_string(&config).unwrap();
57
58 assert!(json.contains("\"profile_name\":\"torrust-profile\""));
59 }
60
61 #[test]
62 fn it_should_deserialize_from_json_when_valid_json_provided() {
63 let json = r#"{"profile_name":"torrust-profile"}"#;
64 let config: LxdConfig = serde_json::from_str(json).unwrap();
65
66 assert_eq!(config.profile_name.as_str(), "torrust-profile");
67 }
68
69 #[test]
70 fn it_should_be_cloneable_when_cloned() {
71 let config = LxdConfig {
72 profile_name: ProfileName::new("test").unwrap(),
73 };
74 let cloned = config.clone();
75 assert_eq!(config, cloned);
76 }
77
78 #[test]
79 fn it_should_implement_debug_trait_when_formatted() {
80 let config = LxdConfig {
81 profile_name: ProfileName::new("test").unwrap(),
82 };
83 let debug = format!("{config:?}");
84 assert!(debug.contains("LxdConfig"));
85 assert!(debug.contains("profile_name"));
86 }
87}