use super::{ask, flat, wired};
use crate::channel::entries::WIRE;
use crate::channel::material::ADDRESS;
use crate::cli::Stream;
use crate::test_support::{Scratch, mint};
use serde_json::json;
#[test]
fn a_box_with_no_wire_names_the_directory_and_the_operator_s_act() {
let scratch = Scratch::new();
let verdict = ask(scratch.path(), &json!({"op": "workspaces"}));
assert_eq!(verdict.code, 1);
assert!(
verdict.text.contains("no wire provisioned"),
"{}",
verdict.text
);
assert!(
verdict.text.contains("carried here by hand"),
"{}",
verdict.text
);
assert!(!verdict.text.contains("usage:"), "{}", verdict.text);
}
#[test]
fn a_half_provisioned_flat_root_says_which_file_is_missing() {
let scratch = Scratch::new();
let dir = scratch.dir(WIRE);
mint::provisioned(&dir, "engine.example:9000");
std::fs::remove_file(dir.join(ADDRESS)).expect("rm");
let verdict = ask(scratch.path(), &json!({"op": "workspaces"}));
assert_eq!(verdict.code, 1);
assert!(
verdict.text.contains("half-provisioned"),
"{}",
verdict.text
);
}
#[test]
fn a_self_provisioned_loopback_root_says_a_seat_wants_a_stated_address() {
let scratch = Scratch::new();
mint::provisioned(&scratch.dir(WIRE), "127.0.0.1:0");
let verdict = ask(scratch.path(), &json!({"op": "workspaces"}));
assert_eq!(verdict.code, 1);
assert!(
verdict.text.contains("kernel-chosen port"),
"{}",
verdict.text
);
assert!(
verdict.text.contains("a seat wants a stated address"),
"{}",
verdict.text
);
}
#[test]
fn an_engine_that_is_not_there_fails_with_the_transport_s_sentence() {
let scratch = Scratch::new();
mint::provisioned(&scratch.dir(WIRE), "127.0.0.1:1");
let verdict = ask(scratch.path(), &json!({"op": "workspaces"}));
assert_eq!(verdict.code, 1);
assert_eq!(verdict.stream, Stream::Err);
assert!(
verdict.text.contains("connect 127.0.0.1:1"),
"{}",
verdict.text
);
}
#[test]
fn a_refusing_reply_is_still_the_product_and_only_the_code_says_no() {
let scratch = Scratch::new();
let refusal = json!({"ok": false, "said": "no such workspace"});
wired(
&scratch,
&flat(),
vec![vec![json!({"ok": true}), refusal.clone()]],
);
let verdict = ask(scratch.path(), &json!({"op": "workspaces"}));
assert_eq!(verdict.code, 1);
assert_eq!(verdict.stream, Stream::Out, "an answer is not a diagnosis");
assert_eq!(
verdict.text,
format!("{}\n{}", json!({"ok": true}), refusal),
"every frame is the product, in order"
);
}
#[test]
fn an_engine_that_answers_nothing_is_not_ok() {
let scratch = Scratch::new();
wired(&scratch, &flat(), vec![vec![]]);
let verdict = ask(scratch.path(), &json!({"op": "workspaces"}));
assert_eq!(verdict.code, 1);
assert_eq!(verdict.text, "");
}