swarm-controller: one test constructor for AppState fixtures
This commit is contained in:
parent
352af3ea59
commit
8d8fcb59cf
1 changed files with 50 additions and 234 deletions
|
|
@ -198,6 +198,47 @@ pub(crate) struct AppState {
|
|||
pub(crate) alerts: Option<Arc<alerts::Grafana>>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl AppState {
|
||||
/// The state every handler test starts from: one hive, `pr1ma`, no queue
|
||||
/// behind any reader, an empty in-memory job graph, and an in-memory
|
||||
/// account store. A test that needs more sets those fields with
|
||||
/// struct-update syntax (`..AppState::for_test()`).
|
||||
pub(crate) fn for_test() -> Self {
|
||||
Self {
|
||||
hives: Arc::new(vec![HiveEntry {
|
||||
name: "pr1ma".to_owned(),
|
||||
domain: "pr1ma.example".to_owned(),
|
||||
dashboard: "pr1ma.hives.example".to_owned(),
|
||||
}]),
|
||||
links: Arc::new(Vec::new()),
|
||||
status: None,
|
||||
wanted: None,
|
||||
agent_status: None,
|
||||
agent_icons: None,
|
||||
agents_md: None,
|
||||
reported_inference: None,
|
||||
agent_login: None,
|
||||
jobq: Arc::new(Mutex::new(hive_jobq::scheduler::Scheduler::new(
|
||||
hive_jobq::Graph::new(),
|
||||
hive_jobq::resources::ResourceTable::new(),
|
||||
))),
|
||||
webhook_secret: Arc::default(),
|
||||
config_prs: Arc::default(),
|
||||
swarm_name: None,
|
||||
auth: None,
|
||||
forge: Arc::default(),
|
||||
create_gate: Arc::default(),
|
||||
accounts: linked_accounts::Accounts::Fake(Arc::default()),
|
||||
try_outs: review_classifier::TryOuts::default(),
|
||||
reviews: Arc::default(),
|
||||
runs: review_classifier::runs::Runs::Live(None),
|
||||
builds: builder::runs::Builds::Live(None),
|
||||
alerts: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Why the status route answers 503 rather than an empty list.
|
||||
///
|
||||
/// "I cannot reach the store" and "every hive is silent" are different
|
||||
|
|
@ -456,45 +497,8 @@ pub(crate) mod tests {
|
|||
>;
|
||||
|
||||
pub(crate) fn state_with_roster() -> (super::AppState, SharedSched) {
|
||||
let sched =
|
||||
std::sync::Arc::new(std::sync::Mutex::new(hive_jobq::scheduler::Scheduler::new(
|
||||
hive_jobq::Graph::new(),
|
||||
hive_jobq::resources::ResourceTable::new(),
|
||||
)));
|
||||
let state = super::AppState {
|
||||
hives: std::sync::Arc::new(vec![HiveEntry {
|
||||
name: "pr1ma".to_owned(),
|
||||
domain: "pr1ma.example".to_owned(),
|
||||
dashboard: "pr1ma.hives.example".to_owned(),
|
||||
}]),
|
||||
links: std::sync::Arc::new(Vec::new()),
|
||||
status: None,
|
||||
// No queue, for the same reason as `status`: these tests build
|
||||
// the creation graph and read its shape, and never run the node
|
||||
// that would write a declaration.
|
||||
wanted: None,
|
||||
agent_status: None,
|
||||
agent_icons: None,
|
||||
agents_md: None,
|
||||
reported_inference: None,
|
||||
agent_login: None,
|
||||
jobq: std::sync::Arc::clone(&sched),
|
||||
webhook_secret: std::sync::Arc::default(),
|
||||
config_prs: std::sync::Arc::default(),
|
||||
swarm_name: None,
|
||||
// No bridge: these tests drive agent *creation*, which queues a
|
||||
// job and consults one only for a rule-breaking name. The roster
|
||||
// read is the verb that needs it, and it has its own test below.
|
||||
auth: None,
|
||||
forge: std::sync::Arc::default(),
|
||||
create_gate: std::sync::Arc::default(),
|
||||
accounts: crate::linked_accounts::Accounts::Fake(std::sync::Arc::default()),
|
||||
try_outs: crate::review_classifier::TryOuts::default(),
|
||||
reviews: std::sync::Arc::default(),
|
||||
runs: crate::review_classifier::runs::Runs::Live(None),
|
||||
builds: crate::builder::runs::Builds::Live(None),
|
||||
alerts: None,
|
||||
};
|
||||
let state = super::AppState::for_test();
|
||||
let sched = std::sync::Arc::clone(&state.jobq);
|
||||
(state, sched)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue