use rigatoni_core::watch_level::WatchLevel;
#[test]
fn test_watch_level_default() {
assert_eq!(WatchLevel::default(), WatchLevel::Database);
}
#[test]
fn test_watch_level_collection() {
let level = WatchLevel::Collection(vec!["users".to_string(), "orders".to_string()]);
assert!(level.is_collection());
assert!(!level.is_database());
assert!(!level.is_deployment());
assert_eq!(
level.collections(),
Some(&vec!["users".to_string(), "orders".to_string()])
);
}
#[test]
fn test_watch_level_database() {
let level = WatchLevel::Database;
assert!(!level.is_collection());
assert!(level.is_database());
assert!(!level.is_deployment());
assert_eq!(level.collections(), None);
}
#[test]
fn test_watch_level_deployment() {
let level = WatchLevel::Deployment;
assert!(!level.is_collection());
assert!(!level.is_database());
assert!(level.is_deployment());
assert_eq!(level.collections(), None);
}
#[test]
fn test_watch_level_description() {
let level = WatchLevel::Collection(vec![]);
assert_eq!(level.description(), "no collections");
let level = WatchLevel::Collection(vec!["users".to_string()]);
assert_eq!(level.description(), "1 collection (users)");
let level = WatchLevel::Collection(vec!["users".to_string(), "orders".to_string()]);
assert_eq!(level.description(), "2 collections");
let level = WatchLevel::Database;
assert_eq!(level.description(), "database");
let level = WatchLevel::Deployment;
assert_eq!(level.description(), "deployment");
}
#[test]
fn test_resume_token_key() {
let level = WatchLevel::Collection(vec!["users".to_string()]);
assert_eq!(
level.resume_token_key("mydb", Some("users")),
"resume_token:mydb:users"
);
let level = WatchLevel::Database;
assert_eq!(
level.resume_token_key("mydb", None),
"resume_token:database:mydb"
);
let level = WatchLevel::Deployment;
assert_eq!(
level.resume_token_key("mydb", None),
"resume_token:deployment"
);
}
#[test]
fn test_watch_level_display() {
let level = WatchLevel::Collection(vec!["users".to_string()]);
assert_eq!(format!("{}", level), "Collection([\"users\"])");
let level = WatchLevel::Database;
assert_eq!(format!("{}", level), "Database");
let level = WatchLevel::Deployment;
assert_eq!(format!("{}", level), "Deployment");
}
#[test]
fn test_watch_level_equality() {
assert_eq!(WatchLevel::Database, WatchLevel::Database);
assert_eq!(WatchLevel::Deployment, WatchLevel::Deployment);
assert_eq!(
WatchLevel::Collection(vec!["a".to_string()]),
WatchLevel::Collection(vec!["a".to_string()])
);
assert_ne!(WatchLevel::Database, WatchLevel::Deployment);
assert_ne!(
WatchLevel::Collection(vec!["a".to_string()]),
WatchLevel::Collection(vec!["b".to_string()])
);
}
#[test]
fn test_watch_level_clone() {
let level = WatchLevel::Collection(vec!["users".to_string()]);
let cloned = level.clone();
assert_eq!(level, cloned);
}
#[test]
fn test_watch_level_empty_collection() {
let level = WatchLevel::Collection(vec![]);
assert!(level.is_collection());
assert_eq!(level.collections(), Some(&vec![]));
assert_eq!(level.description(), "no collections");
}
#[test]
fn test_resume_token_key_collection_without_name() {
let level = WatchLevel::Collection(vec!["users".to_string()]);
assert_eq!(level.resume_token_key("mydb", None), "resume_token:mydb");
}
#[test]
fn test_watch_level_debug() {
let level = WatchLevel::Collection(vec!["users".to_string()]);
let debug_str = format!("{:?}", level);
assert!(debug_str.contains("Collection"));
assert!(debug_str.contains("users"));
let level = WatchLevel::Database;
assert_eq!(format!("{:?}", level), "Database");
let level = WatchLevel::Deployment;
assert_eq!(format!("{:?}", level), "Deployment");
}