use acton_ern::EntityRoot;
use acton_ern::prelude::*;
#[test]
fn test() -> anyhow::Result<()> {
let ern: Result<Ern, ErnError> = ErnBuilder::new()
.with::<Domain>("acton-internal")?
.with::<Category>("hr")?
.with::<Account>("company123")?
.with::<EntityRoot>("root")?
.with::<Part>("departmentA")?
.with::<Part>("team1")?
.build();
assert!(
ern.is_ok(),
"ern:acton-internal:hr:company123:root/departmentA/team1"
);
let ern = ern?;
assert_eq!(ern.domain().to_string(), "acton-internal");
assert_eq!(ern.category().to_string(), "hr");
assert_eq!(ern.account().to_string(), "company123");
assert_eq!(ern.parts().to_string(), "departmentA/team1");
assert!(ern.root().to_string().starts_with("root_"));
Ok(())
}
#[test]
fn test_v7() -> anyhow::Result<()> {
let ern_left: Result<Ern, ErnError> = ErnBuilder::new()
.with::<Domain>("acton-internal".to_string())?
.with::<Category>("hr".to_string())?
.with::<Account>("company123".to_string())?
.with::<EntityRoot>("root".to_string())?
.with::<Part>("departmentA".to_string())?
.with::<Part>("team1".to_string())?
.build();
let ern_right: Result<Ern, ErnError> = ErnBuilder::new()
.with::<Domain>("acton-internal".to_string())?
.with::<Category>("hr".to_string())?
.with::<Account>("company123".to_string())?
.with::<EntityRoot>("root".to_string())?
.with::<Part>("departmentA".to_string())?
.with::<Part>("team1".to_string())?
.build();
assert!(ern_left.is_ok());
assert!(ern_right.is_ok());
assert_ne!(ern_left?, ern_right?);
Ok(())
}
#[test]
fn test_v5() -> anyhow::Result<()> {
let ern_left: Result<Ern, ErnError> = ErnBuilder::new()
.with::<Domain>("acton-internal".to_string())?
.with::<Category>("hr".to_string())?
.with::<Account>("company123".to_string())?
.with::<EntityRoot>("same".to_string())?
.with::<Part>("departmentA".to_string())?
.with::<Part>("team1".to_string())?
.build();
let ern_right: Result<Ern, ErnError> = ErnBuilder::new()
.with::<Domain>("acton-internal".to_string())?
.with::<Category>("hr".to_string())?
.with::<Account>("company123".to_string())?
.with::<EntityRoot>("same".to_string())?
.with::<Part>("departmentA".to_string())?
.with::<Part>("team1".to_string())?
.build();
assert!(ern_left.is_ok());
assert!(ern_right.is_ok());
let left = ern_left?;
let right = ern_right?;
assert_eq!(left.domain(), right.domain());
assert_eq!(left.category(), right.category());
assert_eq!(left.account(), right.account());
assert_eq!(left.parts(), right.parts());
Ok(())
}
#[test]
fn test_parser() -> anyhow::Result<()> {
let parser: ErnParser =
ErnParser::new("ern:acton-internal:hr:company123:root/departmentA/team1".to_string());
let result = parser.parse();
assert!(
result.is_ok(),
"Parser should return Ok, but returned Err with message: {:?}",
result.err()
);
let ern = result.unwrap();
assert_eq!(
ern.domain().to_string(),
"acton-internal",
"Domain should be 'acton-internal'"
);
assert_eq!(ern.category().to_string(), "hr", "Category should be 'hr'");
assert_eq!(
ern.account().to_string(),
"company123",
"Account should be 'company123'"
);
assert_eq!(
ern.parts().to_string(),
"departmentA/team1",
"Parts should match expected values"
);
Ok(())
}