diff --git a/Cargo.toml b/Cargo.toml index 3a68ac2..ede90c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,8 @@ members = [ "bin/u_run", "bin/u_server", "lib/u_lib", - "lib/u_api_proc_macro" + "lib/u_api_proc_macro", + "integration" ] [profile.release] diff --git a/bin/u_agent/Cargo.toml b/bin/u_agent/Cargo.toml index 85cc2d9..c963c2b 100644 --- a/bin/u_agent/Cargo.toml +++ b/bin/u_agent/Cargo.toml @@ -14,8 +14,4 @@ env_logger = "0.8.3" uuid = "0.6.5" reqwest = { version = "0.11", features = ["json"] } openssl = "*" -u_lib = { version = "*", path = "../../lib/u_lib" } - -[[test]] -name = "integration" -path = "tests/tests.rs" \ No newline at end of file +u_lib = { version = "*", path = "../../lib/u_lib" } \ No newline at end of file diff --git a/bin/u_agent/tests/behaviour.rs b/bin/u_agent/tests/behaviour.rs deleted file mode 100644 index 9bad7ea..0000000 --- a/bin/u_agent/tests/behaviour.rs +++ /dev/null @@ -1,8 +0,0 @@ -use u_agent::process_request; - -type TestResult = Result>; - -#[tokio::test] -async fn test_first_connection() -> TestResult { - Ok(()) -} diff --git a/bin/u_agent/tests/tests.rs b/bin/u_agent/tests/tests.rs deleted file mode 100644 index 4328720..0000000 --- a/bin/u_agent/tests/tests.rs +++ /dev/null @@ -1,2 +0,0 @@ -extern crate u_agent; -mod behaviour; diff --git a/integration/Cargo.toml b/integration/Cargo.toml new file mode 100644 index 0000000..c5cc48c --- /dev/null +++ b/integration/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "integration" +version = "0.1.0" +authors = ["plazmoid "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = { version = "1.2.0", features = ["macros", "rt-multi-thread", "process", "time"] } +log = "^0.4" +env_logger = "0.8.3" +uuid = { version = "0.6.5", features = ["serde", "v4"] } +reqwest = { version = "0.11", features = ["json"] } +serde_json = "1.0" +futures = "0.3.5" + + +[[test]] +name = "integration" +path = "tests/tests.rs" \ No newline at end of file diff --git a/integration/docker-compose.yml b/integration/docker-compose.yml index a080377..e82e0c9 100644 --- a/integration/docker-compose.yml +++ b/integration/docker-compose.yml @@ -33,8 +33,6 @@ services: image: unki/u_db networks: - u_net - #volumes: - # - ../data:/var/lib/postgresql/data expose: - '5432' environment: @@ -72,9 +70,10 @@ services: networks: - u_net volumes: - - ../:/unki/ + - ./:/tests/ + - ~/.cargo/registry:/root/.cargo/registry working_dir: - /unki + /tests/ depends_on: u_agent_1: condition: service_started diff --git a/integration/docker.py b/integration/docker.py index 23a07b3..68abd69 100644 --- a/integration/docker.py +++ b/integration/docker.py @@ -24,13 +24,12 @@ DOCKERFILES = { def docker(args): - try: - cmd = ['docker'] + args - log(f'Running docker command: {cmd}') - return subprocess.check_output(cmd) - except subprocess.CalledProcessError as e: - err(str(e)) - raise + cmd = ['docker'] + args + log(f'Running docker command: {cmd}') + return subprocess.run( + cmd, + check=True, + ) def print_errors(errors): diff --git a/integration/docker_compose.py b/integration/docker_compose.py index 0b71cdc..9ae0fc5 100644 --- a/integration/docker_compose.py +++ b/integration/docker_compose.py @@ -45,12 +45,13 @@ class Compose: if isinstance(cmd, str): cmd = shlex.split(cmd) log(f'Running command "{cmd}" in container {container}') - docker([ + result = docker([ 'exec', '-i', container ] + cmd) log('Ok') + return result def is_alive(self): log('Check if all containers are alive') diff --git a/integration/src/main.rs b/integration/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/integration/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/integration/tests/behaviour.rs b/integration/tests/behaviour.rs new file mode 100644 index 0000000..2d46457 --- /dev/null +++ b/integration/tests/behaviour.rs @@ -0,0 +1,34 @@ +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 = Result>; + +fn url>(url: S) -> Url { + Url::parse(&format!("http://{}:{}/{}", SERVER, PORT, url.as_ref())).unwrap() +} + +async fn unpack(req: impl Future>) -> 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>(_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(()) +} diff --git a/integration/tests/tests.rs b/integration/tests/tests.rs new file mode 100644 index 0000000..b3a413f --- /dev/null +++ b/integration/tests/tests.rs @@ -0,0 +1 @@ +mod behaviour;