first integration test

14-integration-tests
plazmoid 3 years ago
parent 5248ae7ac4
commit 7735596bf0
  1. 3
      Cargo.toml
  2. 4
      bin/u_agent/Cargo.toml
  3. 8
      bin/u_agent/tests/behaviour.rs
  4. 2
      bin/u_agent/tests/tests.rs
  5. 21
      integration/Cargo.toml
  6. 7
      integration/docker-compose.yml
  7. 9
      integration/docker.py
  8. 3
      integration/docker_compose.py
  9. 3
      integration/src/main.rs
  10. 34
      integration/tests/behaviour.rs
  11. 1
      integration/tests/tests.rs

@ -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]

@ -15,7 +15,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"

@ -1,8 +0,0 @@
use u_agent::process_request;
type TestResult<R = ()> = Result<R, Box<dyn std::error::Error>>;
#[tokio::test]
async fn test_first_connection() -> TestResult {
Ok(())
}

@ -1,2 +0,0 @@
extern crate u_agent;
mod behaviour;

@ -0,0 +1,21 @@
[package]
name = "integration"
version = "0.1.0"
authors = ["plazmoid <kronos44@mail.ru>"]
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"

@ -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

@ -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
return subprocess.run(
cmd,
check=True,
)
def print_errors(errors):

@ -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')

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

@ -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<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(())
}

@ -0,0 +1 @@
mod behaviour;
Loading…
Cancel
Save