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.
35 lines
1.0 KiB
35 lines
1.0 KiB
3 years ago
|
use futures::Future;
|
||
|
use reqwest::{Response, Result as RResult, Url};
|
||
|
use serde_json::{from_str, Value};
|
||
|
use uuid::Uuid;
|
||
|
|
||
|
const SERVER: &str = "u_server";
|
||
|
const PORT: &str = "63714";
|
||
|
|
||
|
type TestResult<R = ()> = Result<R, Box<dyn std::error::Error>>;
|
||
|
|
||
|
fn url<S: AsRef<str>>(url: S) -> Url {
|
||
|
Url::parse(&format!("http://{}:{}/{}", SERVER, PORT, url.as_ref())).unwrap()
|
||
|
}
|
||
|
|
||
|
async fn unpack(req: impl Future<Output = RResult<Response>>) -> Value {
|
||
|
let resp = req.await.unwrap().text().await.unwrap();
|
||
|
let resp: Value = from_str(&resp).unwrap();
|
||
|
resp.get("inner").unwrap().get(0).unwrap().clone()
|
||
|
}
|
||
|
|
||
|
async fn get<S: AsRef<str>>(_url: S) -> Value {
|
||
|
let req = reqwest::get(url(_url));
|
||
|
unpack(req).await
|
||
|
}
|
||
|
|
||
|
#[tokio::test]
|
||
|
async fn test_first_connection() -> TestResult {
|
||
|
let agent_uid = Uuid::new_v4();
|
||
|
let resp = get(format!("get_agent_jobs/{}", agent_uid)).await;
|
||
|
let job_id = &resp["job_id"];
|
||
|
let resp = get(format!("get_jobs/{}", job_id)).await;
|
||
|
assert_eq!(&resp["alias"], "agent_hello");
|
||
|
Ok(())
|
||
|
}
|