use super::{Where, config, lineages};
use crate::envelope;
use serde_json::json;
#[test]
fn the_lineages_row_builds_the_envelope_its_word_names() {
assert_eq!(
lineages("home".to_owned()),
json!({"op": "lineages", "workspace": "home"})
);
assert_eq!(super::LINEAGES.usage(), "lernie lineages <workspace>");
}
#[test]
fn every_destination_is_the_target_the_wire_spells_and_carries_no_text() {
for (at, target) in [
(
Where::Brazen {
workspace: "home".to_owned(),
},
json!({"file": "brazen", "workspace": "home"}),
),
(Where::LitanyModels, json!({"file": "litany-models"})),
(
Where::LitanyWorkflow {
name: "review".to_owned(),
},
json!({"file": "litany-workflow", "name": "review"}),
),
(Where::Cadence, json!({"file": "cadence"})),
(
Where::Branch {
workspace: "home".to_owned(),
lineage: "default".to_owned(),
path: "providers.yaml".to_owned(),
},
json!({"file": "branch", "workspace": "home", "lineage": "default",
"path": "providers.yaml", "origin": "advance"}),
),
] {
let built = config(&at);
assert_eq!(built[envelope::OP], json!("config"), "{}", at.label());
assert_eq!(built[envelope::TARGET], target, "{}", at.label());
assert!(
built.get("text").is_none(),
"a read carries no text: {built}"
);
}
}
#[test]
fn only_the_two_workspace_destinations_are_routed_by_an_address() {
let branch = Where::Branch {
workspace: "home".to_owned(),
lineage: "default".to_owned(),
path: "providers.yaml".to_owned(),
};
for at in [
Where::Brazen {
workspace: "home".to_owned(),
},
branch.clone(),
] {
assert!(at.addresses_a_workspace(), "{}", at.label());
assert_eq!(
envelope::workspace(&config(&at)).as_deref(),
Some("home"),
"and the seat reads that address off the nested target"
);
}
for at in [
Where::LitanyModels,
Where::Cadence,
Where::LitanyWorkflow {
name: "review".to_owned(),
},
] {
assert!(!at.addresses_a_workspace(), "{}", at.label());
assert_eq!(envelope::workspace(&config(&at)), None);
}
assert_eq!(branch.label(), "default: providers.yaml");
assert_eq!(Where::LitanyModels.label(), "litany models");
assert_eq!(
Where::LitanyWorkflow {
name: "review".to_owned()
}
.label(),
"workflow review"
);
assert_eq!(Where::Cadence.label(), "cadence");
assert_eq!(
Where::Brazen {
workspace: "home".to_owned()
}
.label(),
"brazen"
);
}