use super::*;
use crate::opslog::OpRow;
fn act(verb: &str, ball: &str) -> OpRow {
let entry = if verb == crate::fleet::row::REAP {
crate::fleet::row::reaped(
"1".to_owned(),
Path::new(WS),
ball,
"otter",
"lease expired 1m ago",
)
} else {
crate::fleet::row::spawned("1".to_owned(), Path::new(WS), ball, "OtterBrook")
};
OpRow::from(&entry)
}
fn with(ops: Vec<OpRow>) -> Snapshot {
Snapshot {
ops,
..snap(vec![])
}
}
#[test]
fn a_reaped_ball_is_not_retaken_and_the_next_ready_ball_runs() {
let board = vec![
row("bl-high", Column::Ready, vec![]),
row("bl-low", Column::Ready, vec![]),
];
let one = plan(
&with(vec![act(crate::fleet::row::REAP, "bl-high")]),
&facts(1, 0, None),
Path::new(fixture::WS),
&board,
NOW,
);
let Some(Move::Spawn { row }) = one else {
panic!("a spawn");
};
assert_eq!(
row.id, "bl-low",
"the board's first ready ball is the one the loop just gave back"
);
}
#[test]
fn a_reaped_ball_alone_on_the_board_stops_the_loop_rather_than_looping() {
let board = vec![row("bl-high", Column::Ready, vec![])];
assert_eq!(
plan(
&with(vec![act(crate::fleet::row::REAP, "bl-high")]),
&facts(1, 0, None),
Path::new(fixture::WS),
&board,
NOW
),
None
);
}
#[test]
fn the_newest_act_in_this_workspace_is_the_whole_memory() {
let board = vec![row("bl-high", Column::Ready, vec![])];
let retaken = vec![
act(crate::fleet::row::REAP, "bl-high"),
act(crate::fleet::row::SPAWN, "bl-high"),
];
assert!(
matches!(
plan(
&with(retaken),
&facts(1, 0, None),
Path::new(fixture::WS),
&board,
NOW
),
Some(Move::Spawn { .. })
),
"the newest act is a spawn, so the loop holds it rather than having given it back"
);
let mut elsewhere = act(crate::fleet::row::REAP, "bl-high");
elsewhere.cwd = "/names/heron".to_owned();
assert!(
matches!(
plan(
&with(vec![elsewhere]),
&facts(1, 0, None),
Path::new(fixture::WS),
&board,
NOW
),
Some(Move::Spawn { .. })
),
"another workspace's loop gave that ball back, not this one"
);
}