|
|
|
use crate::fixtures::agent::*;
|
|
|
|
use crate::helpers::Panel;
|
|
|
|
|
|
|
|
use rstest::rstest;
|
|
|
|
use std::error::Error;
|
|
|
|
use std::thread::sleep;
|
|
|
|
use std::time::Duration;
|
|
|
|
use u_lib::models::*;
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
type TestResult<R = ()> = Result<R, Box<dyn Error>>;
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_registration(#[future] register_agent: RegisteredAgent) -> TestResult {
|
|
|
|
let agent = register_agent.await;
|
|
|
|
let agents: Vec<Agent> = Panel::check_output("agents list");
|
|
|
|
let found = agents.iter().find(|v| v.id == agent.uid);
|
|
|
|
assert!(found.is_some());
|
|
|
|
//teardown
|
|
|
|
Panel::check_status::<i32>(&format!("agents delete {}", agent.uid));
|
|
|
|
Ok(()) //TODO: ______^^^^^ REMOV
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_setup_tasks() -> TestResult {
|
|
|
|
//some independent agents should present
|
|
|
|
let agents: Vec<Agent> = Panel::check_output("agents list");
|
|
|
|
let agent_uid = agents[0].id;
|
|
|
|
let job_alias = "passwd_contents";
|
|
|
|
let cmd = format!("jobs add --alias {} 'cat /etc/passwd'", job_alias);
|
|
|
|
Panel::check_status::<Empty>(&cmd);
|
|
|
|
let cmd = format!("jobmap add {} {}", agent_uid, job_alias);
|
|
|
|
let assigned_uids: Vec<Uuid> = Panel::check_output(cmd);
|
|
|
|
for _ in 0..3 {
|
|
|
|
let result: Vec<AssignedJob> =
|
|
|
|
Panel::check_output(format!("jobmap list {}", assigned_uids[0]));
|
|
|
|
if result[0].state == JobState::Finished {
|
|
|
|
return Ok(());
|
|
|
|
} else {
|
|
|
|
sleep(Duration::from_secs(5));
|
|
|
|
eprintln!("waiting for task");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
panic!("Job didn't appear in the job map");
|
|
|
|
}
|