move tests
This commit is contained in:
		
							
								
								
									
										59
									
								
								tests/config_serialization.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								tests/config_serialization.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
			
		||||
use dynip_cloudflare::Config;
 | 
			
		||||
use std::time::Duration;
 | 
			
		||||
use toml;
 | 
			
		||||
 | 
			
		||||
const TOML_STR_ONE: &str = r#"
 | 
			
		||||
zone_id = ""
 | 
			
		||||
api_key = ""
 | 
			
		||||
domains = [""]
 | 
			
		||||
max_duration = "1d 2h 30m 45s 500000000ns"
 | 
			
		||||
"#;
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn test_deserialize() {
 | 
			
		||||
    let config: Config = toml::from_str(TOML_STR_ONE).unwrap();
 | 
			
		||||
    assert_eq!(config.max_duration, Some(Duration::new(95445, 500000000)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn test_serialize() {
 | 
			
		||||
    let config = Config {
 | 
			
		||||
        zone_id: "".into(),
 | 
			
		||||
        api_key: "".into(),
 | 
			
		||||
        domains: vec!["".into()],
 | 
			
		||||
        max_errors_in_row: None,
 | 
			
		||||
        max_duration: Some(Duration::new(95445, 500000000)),
 | 
			
		||||
    };
 | 
			
		||||
    let toml_str = toml::to_string(&config).unwrap();
 | 
			
		||||
    assert_eq!(TOML_STR_ONE.trim(), toml_str.trim());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn test_deserialize_none() {
 | 
			
		||||
    let toml_str = r#"
 | 
			
		||||
zone_id = ""
 | 
			
		||||
api_key = ""
 | 
			
		||||
domains = [""]
 | 
			
		||||
max_errors_in_row = 5
 | 
			
		||||
"#;
 | 
			
		||||
    let config: Config = toml::from_str(toml_str).unwrap();
 | 
			
		||||
    assert_eq!(config.max_duration, None);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn test_serialize_none() {
 | 
			
		||||
    let toml_to_be = r#"
 | 
			
		||||
zone_id = ""
 | 
			
		||||
api_key = ""
 | 
			
		||||
domains = [""]
 | 
			
		||||
"#;
 | 
			
		||||
    let config = Config {
 | 
			
		||||
        zone_id: "".into(),
 | 
			
		||||
        api_key: "".into(),
 | 
			
		||||
        domains: vec!["".into()],
 | 
			
		||||
        max_errors_in_row: None,
 | 
			
		||||
        max_duration: None,
 | 
			
		||||
    };
 | 
			
		||||
    let toml_str = toml::to_string(&config).unwrap();
 | 
			
		||||
    assert_eq!(toml_to_be.trim(), toml_str.trim());
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user