//! A runtime that records what it is asked to run, for the runner and broker tests. Do not edit. //! //! Included with `#[path = "support/runtime.rs"] mod runtime;`. #![allow(dead_code)] // each test file uses a different part of this module use std::sync::{Arc, Mutex}; use brokerd::args::{ToolArgs, ToolName}; use brokerd::runner::{Mount, RunError, RunOutput, RunSpec, Runtime}; /// What one `run` was given, copied out of the `RunSpec`. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Seen { pub tool: ToolName, pub arguments: ToolArgs, pub mounts: Vec, pub egress: Option>, } pub struct Recording { seen: Mutex>, answer: Result, } impl Recording { /// Answers every call with `content`, not truncated. pub fn answering(content: &str) -> Arc { Recording::with(Ok(RunOutput { content: content.to_string(), truncated: false, })) } pub fn with(answer: Result) -> Arc { Arc::new(Recording { seen: Mutex::new(Vec::new()), answer, }) } pub fn seen(&self) -> Vec { self.seen.lock().unwrap().clone() } pub fn count(&self) -> usize { self.seen.lock().unwrap().len() } } impl Runtime for Recording { fn run(&self, spec: &RunSpec) -> Result { self.seen.lock().unwrap().push(Seen { tool: spec.tool(), arguments: spec.arguments().clone(), mounts: spec.mounts().to_vec(), egress: spec.egress().map(<[String]>::to_vec), }); self.answer.clone() } } /// Lets a test keep its `Arc` while the broker owns a `Box`. pub struct Shared(pub Arc); impl Runtime for Shared { fn run(&self, spec: &RunSpec) -> Result { self.0.run(spec) } }