test the archetype module import in the meta flake render; update archetypes doc
This commit is contained in:
parent
b6b568e97e
commit
88053f437c
3 changed files with 80 additions and 20 deletions
|
|
@ -617,6 +617,55 @@ mod tests {
|
|||
assert!(!builds_agent_at(&flake, "ghost", Some(&reviewer()), None));
|
||||
}
|
||||
|
||||
/// The text of `mkAgent`'s `let` binding `name`: from `name =` to the
|
||||
/// next binding at the same indent (`;` ends it at line end).
|
||||
fn binding<'a>(flake: &'a str, name: &str) -> &'a str {
|
||||
let from = flake
|
||||
.find(&format!("\n {name} =\n"))
|
||||
.or_else(|| flake.find(&format!("\n {name} = ")))
|
||||
.unwrap_or_else(|| panic!("no `{name}` binding in mkAgent"));
|
||||
let rest = &flake[from + 1..];
|
||||
let end = rest
|
||||
.find("\n service =")
|
||||
.unwrap_or_else(|| panic!("`{name}` is the last binding"));
|
||||
&rest[..end]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_archetype_agent_s_module_is_the_archetype_source_s_module() {
|
||||
let flake = rendered();
|
||||
let module = binding(&flake, "agentModule");
|
||||
assert!(
|
||||
module.contains("archetypeSources.${archetype.source}"),
|
||||
"the archetype branch picks its source by name: {module}"
|
||||
);
|
||||
assert!(
|
||||
module.contains(".hyperhiveArchetypes.${archetype.name}.module"),
|
||||
"the archetype branch imports the archetype's module: {module}"
|
||||
);
|
||||
// The source it picks from must offer the hyperhive input.
|
||||
assert!(
|
||||
binding(&flake, "archetypeSources").contains("inherit hyperhive;"),
|
||||
"the `hyperhive` archetype source"
|
||||
);
|
||||
// The module reaches the agent's system.
|
||||
let modules = &flake[flake.find("modules = [").expect("a module list")..];
|
||||
assert!(
|
||||
modules
|
||||
.trim_start_matches("modules = [")
|
||||
.trim_start()
|
||||
.starts_with("agentModule"),
|
||||
"agentModule heads the extendModules list"
|
||||
);
|
||||
// The entry names the source and archetype the import reads.
|
||||
assert!(
|
||||
flake.contains("rev = mkAgent { name = \"rev\"; port = ")
|
||||
&& flake
|
||||
.contains(" archetype = { source = \"hyperhive\"; name = \"reviewer\"; }; };"),
|
||||
"the archetype agent's entry"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_agent_whose_name_ends_another_s_is_not_that_agent() {
|
||||
let flake = rendered();
|
||||
|
|
|
|||
Loading…
Reference in a new issue