mod helpers; use helpers::Panel; use std::error::Error; use std::thread::sleep; use std::time::Duration; use u_lib::{api::ClientHandler, models::*}; use uuid::Uuid; type TestResult = Result>; async fn register_agent() -> Uuid { let cli = ClientHandler::new(None); let agent_uid = Uuid::new_v4(); let resp = cli .get_personal_jobs(Some(agent_uid)) .await .unwrap() .pop() .unwrap(); let job_id = resp.job_id; let resp = cli.get_jobs(Some(job_id)).await.unwrap().pop().unwrap(); assert_eq!(resp.alias, Some("agent_hello".to_string())); let agent_data = Agent { id: agent_uid, ..Default::default() }; cli.report(&vec![ExecResult::Agent(agent_data)]) .await .unwrap(); agent_uid } #[tokio::test] async fn test_registration() -> TestResult { let agent_uid = register_agent().await; let agents: Vec = Panel::check_output("agents list"); let found = agents.iter().find(|v| v.id == agent_uid); assert!(found.is_some()); //teardown 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 = 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 = Panel::check_output(cmd); for _ in 0..3 { let result: Vec = 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!() }