use std::os::fd::RawFd;
use std::path::PathBuf;
use shep_core::config::AppConfig;
use shep_core::status::ProcStatus;
use super::{Candidate, CarriedFds, CarriedSheep};
use crate::entry::{ProcessEntry, ReloadState, RestartBudget};
use crate::privilege::SpawnIdentity;
use crate::testing::app_with;
pub(super) fn entry_fixture(mutate: impl FnOnce(&mut AppConfig)) -> ProcessEntry {
let spec = app_with("web", mutate);
ProcessEntry {
id: 1,
spec,
pending: None,
pending_reidentifies: false,
overridden: Vec::new(),
instance: 0,
status: ProcStatus::Online,
pid: Some(100),
restarts: 0,
started_at: None,
budget: RestartBudget::default(),
reload: ReloadState::None,
credentials: SpawnIdentity::Resolved(None),
out_file: PathBuf::from("/tmp/shep-handover-test-out.log"),
err_file: PathBuf::from("/tmp/shep-handover-test-err.log"),
dog: None,
last_exit: None,
}
}
pub(super) fn plain(entry: &ProcessEntry) -> Candidate<'_> {
Candidate {
entry,
pump_unresponsive: false,
}
}
pub(super) fn wedged(entry: &ProcessEntry) -> Candidate<'_> {
Candidate {
entry,
pump_unresponsive: true,
}
}
pub(super) const fn fds_at(base: RawFd) -> CarriedFds {
CarriedFds {
out_pipe: Some(base),
err_pipe: Some(base + 1),
out_log: Some(base + 2),
err_log: Some(base + 3),
stdin: Some(base + 4),
channel: Some(base + 5),
}
}
pub(super) fn carried(entry: &ProcessEntry) -> CarriedSheep {
CarriedSheep::from_entry(entry, 7, fds_at(11), false, None, false, None)
}