use super::super::*;
use crate::fake::ScriptedRunner;
use crate::supervisor::spawn_supervisor;
use crate::testing::test_paths;
use shep_core::paths::ShepPaths;
pub(crate) struct TestFlock {
pub(crate) paths: ShepPaths,
pub(crate) handle: SupervisorHandle,
pub(crate) registry: FlockRegistry,
pub(crate) events: Bus,
_dir: tempfile::TempDir,
_rx: broadcast::Receiver<SharedEvent>,
}
impl TestFlock {
#[track_caller]
pub(crate) fn new(runner: ScriptedRunner) -> Self {
let dir = tempfile::tempdir().expect("a test must be able to make a tempdir");
let paths = test_paths(&dir);
std::fs::create_dir_all(
paths
.snapshot
.parent()
.expect("a roll path always has a parent"),
)
.expect("the test's $SHEP_HOME layout must be creatable");
let (events, rx) = crate::bus::test_bus(64);
let handle = spawn_supervisor(runner, paths.clone(), events.clone());
Self {
paths,
handle,
registry: FlockRegistry::new(),
events,
_dir: dir,
_rx: rx,
}
}
#[track_caller]
pub(crate) fn seed(&self, roll: &FlockSnapshot) {
write_atomic(&self.paths.snapshot, roll).expect("the fixture roll must be writable");
}
pub(crate) async fn muster(&self) -> Result<Vec<String>, SnapshotError> {
muster(
&self.paths.snapshot,
&self.registry,
&self.handle,
&self.events,
&[],
&[],
None,
)
.await
}
pub(crate) async fn shutdown(self) {
self.handle.shutdown().await;
}
}