You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.5 KiB

use crate::fixtures::agent::*;
use crate::helpers::Panel;
use rstest::rstest;
use std::error::Error;
use std::time::Duration;
use tokio::time::sleep;
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());
Panel::check_status(format!("agents delete {}", agent.uid));
Ok(())
}
#[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(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)).await;
eprintln!("waiting for task");
}
}
panic!("Job didn't appear in the job map");
}