use std::time::Duration;
#[derive(Debug, Clone, Default)]
pub struct DialOptions {
pub timeout: Option<Duration>,
pub identity: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub struct ListenOptions {
pub identity: Option<String>,
pub cost: Option<u16>,
pub precedence: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
use std::time::Duration;
#[test]
fn test_dial_options_default() {
let options = DialOptions::default();
assert_eq!(options.timeout, None);
assert_eq!(options.identity, None);
}
#[test]
fn test_dial_options_custom() {
let options = DialOptions {
timeout: Some(Duration::from_secs(60)),
identity: Some("my-identity".to_string()),
};
assert_eq!(options.timeout, Some(Duration::from_secs(60)));
assert_eq!(options.identity, Some("my-identity".to_string()));
}
#[test]
fn test_dial_options_partial() {
let options = DialOptions {
timeout: Some(Duration::from_millis(5000)),
identity: None,
};
assert_eq!(options.timeout, Some(Duration::from_millis(5000)));
assert_eq!(options.identity, None);
}
#[test]
fn test_listen_options_default() {
let options = ListenOptions::default();
assert_eq!(options.identity, None);
assert_eq!(options.cost, None);
assert_eq!(options.precedence, None);
}
#[test]
fn test_listen_options_custom() {
let options = ListenOptions {
identity: Some("server-identity".to_string()),
cost: Some(100),
precedence: Some("high".to_string()),
};
assert_eq!(options.identity, Some("server-identity".to_string()));
assert_eq!(options.cost, Some(100));
assert_eq!(options.precedence, Some("high".to_string()));
}
#[test]
fn test_listen_options_partial() {
let options = ListenOptions {
identity: None,
cost: Some(50),
precedence: None,
};
assert_eq!(options.identity, None);
assert_eq!(options.cost, Some(50));
assert_eq!(options.precedence, None);
}
#[test]
fn test_dial_options_clone() {
let original = DialOptions {
timeout: Some(Duration::from_secs(30)),
identity: Some("test".to_string()),
};
let cloned = original.clone();
assert_eq!(cloned.timeout, original.timeout);
assert_eq!(cloned.identity, original.identity);
}
#[test]
fn test_listen_options_clone() {
let original = ListenOptions {
identity: Some("test".to_string()),
cost: Some(200),
precedence: Some("normal".to_string()),
};
let cloned = original.clone();
assert_eq!(cloned.identity, original.identity);
assert_eq!(cloned.cost, original.cost);
assert_eq!(cloned.precedence, original.precedence);
}
}