use crate::lookout::app::{App, Control};
use crate::lookout::source::{HostSample, Local};
use crate::lookout::tail::Tail;
use crate::lookout::theme::Palette;
use shep_core::paths::ShepPaths;
use std::path::Path;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Instant;
pub(super) fn test_paths(home: &Path) -> ShepPaths {
let home_str = home.to_string_lossy().into_owned();
ShepPaths::resolve(&|key| (key == "SHEP_HOME").then(|| home_str.clone()), home)
}
pub(super) fn shared_test_paths() -> ShepPaths {
test_paths(Path::new("/tmp/shep-lookout-tests"))
}
pub(super) fn read_only_app() -> App {
App::new(
Palette::detect(None, None, None),
Control::ReadOnly,
"/tmp/shep".to_string(),
Instant::now(),
)
}
#[derive(Clone, Default)]
pub(super) struct FakeLocal {
pub(super) sample: Option<HostSample>,
pub(super) hosts: Arc<AtomicUsize>,
pub(super) tails: Arc<AtomicUsize>,
pub(super) log_sizes: Arc<AtomicUsize>,
}
impl Local for FakeLocal {
fn host(&mut self) -> Option<HostSample> {
self.hosts.fetch_add(1, Ordering::Relaxed);
self.sample
}
fn tail(&mut self, _out: Option<&Path>, _err: Option<&Path>) -> Tail {
self.tails.fetch_add(1, Ordering::Relaxed);
Tail::default()
}
fn log_sizes(&mut self, _out: Option<&Path>, _err: Option<&Path>) -> Option<u64> {
self.log_sizes.fetch_add(1, Ordering::Relaxed);
None
}
}
pub(super) fn kelpie_answer() -> serde_json::Value {
serde_json::from_str(include_str!("kelpie-schema.json")).expect("the recording is JSON")
}
pub(super) fn kelpie_sheep_schema() -> serde_json::Value {
super::probe_sheep_dogs::sheep_schema(&kelpie_answer()).expect("the answer names x-shep-sheep")
}