parent
32e96476cf
commit
45bba0dd9b
20 changed files with 419 additions and 168 deletions
@ -1,3 +1,3 @@ |
|||||||
FROM alpine:3.17 |
FROM alpine:3.17 |
||||||
|
|
||||||
RUN apk add iproute2 bash |
RUN apk add iproute2 bash file |
@ -1,46 +0,0 @@ |
|||||||
// get_personal_jobs(&self, url_param: Id)
|
|
||||||
// report(&self, payload: impl OneOrVec<messaging::Reportable>)
|
|
||||||
// dl(&self, file: String)
|
|
||||||
// get_job(&self, job: Id)
|
|
||||||
// get_jobs(&self)
|
|
||||||
// get_agents(&self, agent: Option<Id>)
|
|
||||||
// update_agent(&self, agent: Agent)
|
|
||||||
// update_job(&self, job: FatJob)
|
|
||||||
// update_result(&self, result: AssignedJob)
|
|
||||||
// upload_jobs(&self, payload: impl OneOrVec<FatJob>)
|
|
||||||
// del(&self, item: Id)
|
|
||||||
// set_jobs(&self, agent: Id, job_idents: impl OneOrVec<String>)
|
|
||||||
// get_agent_jobs(&self, agent: Option<Id>)
|
|
||||||
// ping(&self)
|
|
||||||
|
|
||||||
use crate::fixtures::connections::*; |
|
||||||
use u_lib::models::RawJob; |
|
||||||
|
|
||||||
#[rstest] |
|
||||||
#[tokio::test] |
|
||||||
async fn test_jobs_endpoints(client_panel: &HttpClient) { |
|
||||||
let job_alias = "henlo"; |
|
||||||
let mut job = RawJob::builder() |
|
||||||
.with_shell("echo henlo") |
|
||||||
.with_alias(job_alias) |
|
||||||
.build() |
|
||||||
.unwrap(); |
|
||||||
|
|
||||||
let job_id = job.job.id; |
|
||||||
|
|
||||||
client_panel.upload_jobs([&job]).await.unwrap(); |
|
||||||
|
|
||||||
let fetched_job = client_panel.get_brief_job(job_id).await.unwrap(); |
|
||||||
assert_eq!(job, fetched_job); |
|
||||||
|
|
||||||
job.job.alias = Some("henlo2".to_string()); |
|
||||||
client_panel.update_job(&job).await.unwrap(); |
|
||||||
|
|
||||||
let fetched_job = client_panel.get_brief_job(job_id).await.unwrap(); |
|
||||||
assert_eq!(job, fetched_job); |
|
||||||
|
|
||||||
client_panel.del(job_id).await.unwrap(); |
|
||||||
|
|
||||||
let not_found_err = client_panel.get_brief_job(job_id).await.unwrap_err(); |
|
||||||
assert!(not_found_err.to_string().contains("404 Not Found")) |
|
||||||
} |
|
@ -0,0 +1,112 @@ |
|||||||
|
// get_personal_jobs(&self, url_param: Id)
|
||||||
|
// report(&self, payload: impl OneOrVec<messaging::Reportable>)
|
||||||
|
// dl(&self, file: String)
|
||||||
|
// get_job(&self, job: Id)
|
||||||
|
// get_jobs(&self)
|
||||||
|
// get_agents(&self, agent: Option<Id>)
|
||||||
|
// update_agent(&self, agent: Agent)
|
||||||
|
// update_job(&self, job: FatJob)
|
||||||
|
// update_result(&self, result: AssignedJob)
|
||||||
|
// upload_jobs(&self, payload: impl OneOrVec<FatJob>)
|
||||||
|
// del(&self, item: Id)
|
||||||
|
// set_jobs(&self, agent: Id, job_idents: impl OneOrVec<String>)
|
||||||
|
// get_agent_jobs(&self, agent: Option<Id>)
|
||||||
|
// ping(&self)
|
||||||
|
|
||||||
|
use crate::fixtures::connections::*; |
||||||
|
use std::iter::repeat; |
||||||
|
use u_lib::models::{BriefMode, RawJob, RawPayload, MAX_READABLE_PAYLOAD_SIZE}; |
||||||
|
|
||||||
|
#[rstest] |
||||||
|
#[tokio::test] |
||||||
|
async fn jobs_upload_update_get_del(client_panel: &HttpClient) { |
||||||
|
let job_alias = "henlo"; |
||||||
|
let mut job = RawJob::builder() |
||||||
|
.with_shell("/bin/bash {}") |
||||||
|
.with_raw_payload("echo henlo") |
||||||
|
.with_alias(job_alias) |
||||||
|
.build() |
||||||
|
.unwrap(); |
||||||
|
|
||||||
|
let job_id = job.job.id; |
||||||
|
|
||||||
|
client_panel.upload_jobs([&job]).await.unwrap(); |
||||||
|
|
||||||
|
let fetched_job = client_panel.get_full_job(job_id).await.unwrap(); |
||||||
|
assert_eq!(job, fetched_job); |
||||||
|
|
||||||
|
// update job's payload by edit existing does nothing,
|
||||||
|
// editing is only allowed from payload itself
|
||||||
|
*job.payload.as_mut().unwrap().data.as_mut().unwrap() = b"echo henlo2".to_vec(); |
||||||
|
client_panel.update_job(&job).await.unwrap(); |
||||||
|
|
||||||
|
let fetched_job = client_panel.get_full_job(job_id).await.unwrap(); |
||||||
|
assert_eq!( |
||||||
|
fetched_job.payload.as_ref().unwrap().data.as_ref().unwrap(), |
||||||
|
b"echo henlo" |
||||||
|
); |
||||||
|
|
||||||
|
client_panel.del(job_id).await.unwrap(); |
||||||
|
|
||||||
|
let not_found_err = client_panel.get_brief_job(job_id).await.unwrap_err(); |
||||||
|
assert!(not_found_err.to_string().contains("404 Not Found")) |
||||||
|
} |
||||||
|
|
||||||
|
#[rstest] |
||||||
|
#[tokio::test] |
||||||
|
async fn payloads_upload_update_get_del(client_panel: &HttpClient) { |
||||||
|
let name = "test1".to_string(); |
||||||
|
let data = b"qweasdzxc".to_vec(); |
||||||
|
let payload = RawPayload { |
||||||
|
name: name.clone(), |
||||||
|
data: data.clone(), |
||||||
|
}; |
||||||
|
|
||||||
|
client_panel.upload_payloads([&payload]).await.unwrap(); |
||||||
|
|
||||||
|
let mut fetched_payload = client_panel |
||||||
|
.get_payload(&name, BriefMode::No) |
||||||
|
.await |
||||||
|
.unwrap(); |
||||||
|
let fetched_payload_auto = client_panel |
||||||
|
.get_payload(&name, BriefMode::Auto) |
||||||
|
.await |
||||||
|
.unwrap(); |
||||||
|
|
||||||
|
assert_eq!(fetched_payload, fetched_payload_auto); |
||||||
|
assert_eq!(fetched_payload.data.unwrap(), data); |
||||||
|
|
||||||
|
let new_size = MAX_READABLE_PAYLOAD_SIZE + 1; |
||||||
|
let big_data = repeat(1u8).take(new_size as usize).collect::<Vec<_>>(); |
||||||
|
|
||||||
|
fetched_payload.data = Some(big_data.clone()); |
||||||
|
client_panel.update_payload(&fetched_payload).await.unwrap(); |
||||||
|
|
||||||
|
let fetched_big_payload = client_panel |
||||||
|
.get_payload(&name, BriefMode::Yes) |
||||||
|
.await |
||||||
|
.unwrap(); |
||||||
|
let fetched_big_payload_auto = client_panel |
||||||
|
.get_payload(&name, BriefMode::Auto) |
||||||
|
.await |
||||||
|
.unwrap(); |
||||||
|
|
||||||
|
assert_eq!(fetched_big_payload, fetched_big_payload_auto); |
||||||
|
assert_eq!(fetched_big_payload.size, new_size); |
||||||
|
assert!(fetched_big_payload.data.is_none()); |
||||||
|
|
||||||
|
let fetched_big_payload_full = client_panel |
||||||
|
.get_payload(&name, BriefMode::No) |
||||||
|
.await |
||||||
|
.unwrap(); |
||||||
|
|
||||||
|
assert_eq!(fetched_big_payload_full.data.unwrap(), big_data); |
||||||
|
|
||||||
|
client_panel.del(fetched_big_payload_full.id).await.unwrap(); |
||||||
|
|
||||||
|
let not_found_err = client_panel |
||||||
|
.get_payload(&name, BriefMode::Yes) |
||||||
|
.await |
||||||
|
.unwrap_err(); |
||||||
|
assert!(not_found_err.to_string().contains("404 Not Found")) |
||||||
|
} |
@ -1,3 +1,3 @@ |
|||||||
mod api; |
|
||||||
mod behaviour; |
mod behaviour; |
||||||
mod connection; |
mod connection; |
||||||
|
mod endpoints; |
||||||
|
Loading…
Reference in new issue