use super::*;
use crate::fake::{FIRST_SCRIPTED_PID, ProcScript};
use crate::limits::MEMORY_POLL_INTERVAL;
use crate::testing::{
Harness, SCRIPTED_TREE_BYTES, harness, harness_identifying, harness_with_stats, identity,
};
use shep_core::config::{AppConfig, ApplyGroup, DeclaredApp, ResetDepth, apply_group};
use shep_core::protocol::{
ActionOutcome, ActionReply, DogSource, HostUsage, ProcessEventKind, Request, Response,
RpcErrorCode, SelectorSpec,
};
use shep_core::values::UpDuration;
use std::collections::{BTreeMap, BTreeSet};
use tokio::time::Instant;
async fn dispatch(envelope: Envelope, ctx: &RpcContext) -> Outcome {
super::dispatch(envelope, ConnId::next(), ctx).await
}
fn envelope(id: u64, body: Request) -> Envelope {
Envelope {
id,
deadline_ms: None,
body,
}
}
fn reply_of(outcome: Outcome) -> Reply {
match outcome {
Outcome::Reply(reply) | Outcome::Subscribe { reply, .. } | Outcome::Shutdown(reply) => {
reply
}
}
}
async fn start_web(h: &Harness) {
reply_of(
dispatch(
envelope(
1,
Request::Start {
apps: vec![AppConfig::minimal("web", "./srv")],
},
),
&h.ctx,
)
.await,
);
}
async fn list_flock(ctx: &RpcContext, id: u64) -> Vec<ProcessInfo> {
let reply = reply_of(dispatch(envelope(id, Request::ListFlock), ctx).await);
let Ok(Response::Flock(infos)) = reply.result else {
panic!("expected Flock, got {:?}", reply.result)
};
infos
}
async fn enable_dog(ctx: &RpcContext, id: u64, name: &str) -> ProcessInfo {
let reply = reply_of(
dispatch(
envelope(
id,
Request::EnableDog {
name: name.to_string(),
source: DogSource::BuiltIn,
},
),
ctx,
)
.await,
);
let Ok(Response::DogStarted(info)) = reply.result else {
panic!("expected DogStarted, got {:?}", reply.result)
};
info
}
async fn start_web_with_a_secret(ctx: &RpcContext) {
let mut config = AppConfig::minimal("web", "./srv");
config
.env
.insert("DB_PASS".to_string(), "hunter2".to_string());
let started = reply_of(dispatch(envelope(1, Request::Start { apps: vec![config] }), ctx).await);
assert!(started.result.is_ok(), "{:?}", started.result);
}
async fn sheep_config_view(
ctx: &RpcContext,
id: u64,
name: &str,
) -> shep_core::protocol::SheepConfigView {
let reply = reply_of(
dispatch(
envelope(
id,
Request::SheepConfig {
name: name.to_string(),
},
),
ctx,
)
.await,
);
match reply.result {
Ok(Response::SheepConfig(view)) => *view,
other => panic!("expected SheepConfig, got {other:?}"),
}
}
mod apply_config;
mod disable_enable;
mod disable_roll;
mod disabled_reload;
mod disabled_restarts;
mod disabled_wildcards;
mod dog_at_rest;
mod dog_delete;
mod dog_disable;
mod dog_env;
mod dog_fields;
mod dog_lifecycle;
mod dog_secrets;
mod dog_secrets_rotation;
mod dog_table_events;
mod dog_tables;
mod lambs_staleness;
mod misc_verbs;
mod push;
mod sheep_dog_names;
mod start_add;
mod stats;
mod trigger_signal;
mod walk;