Skip to content

Commit

Permalink
Add e2e tests (broken due to issue? in API)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lun4m committed Jun 7, 2024
1 parent 4dc891a commit 2a51dc1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 10 deletions.
1 change: 1 addition & 0 deletions lard_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ bb8-postgres.workspace = true

[dev-dependencies]
reqwest.workspace = true
test-case.workspace = true

[[bin]]
name = "prepare_db"
Expand Down
90 changes: 80 additions & 10 deletions lard_tests/tests/end-to-end_test.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,91 @@
use std::future::Future;

pub mod common;

#[tokio::test]
async fn end_to_end_test() {
async fn e2e_test_wrapper<T: Future<Output = ()>>(test: T) {
let api_server = common::init_api_server().await;
let ingestor = common::init_ingestion_server().await;

let test = async {
// TODO: ingest data
// TODO: test API
println!("Testing that stuff works...");
};

tokio::select! {
_ = api_server => panic!("API server task terminated first"),
// TODO: right now `ingestor` errors out, so it finishes first.
// need to figure out the permission thing
_ = ingestor => panic!("Ingestor server task terminated first"),
_ = test => {}
}
}

#[tokio::test]
async fn existing_timeseries() {
e2e_test_wrapper(async move {
let station_id = 1800;
let param_id = 211;

let client = reqwest::Client::new();
let obsinn_msg = format!(
"kldata/nationalnr={}/type=508/messageid=23
TA,TWD(0,0)
20240607164900,20.0,15.2
20240607165100,20.1,15.3
20240607165200,20.0,15.3
20240607165300,20.2,15.1
20240607165400,20.2,15.2
20240607165500,20.1,15.2
",
station_id
);

let resp = client
.post("http://localhost:3001/kldata")
.body(obsinn_msg)
.send()
.await
.unwrap();
println!("\ningestion resp: {}", resp.text().await.unwrap());

let url = format!(
"http://localhost:3000/stations/{}/params/{}",
station_id, param_id
);
let resp = client.get(url).send().await.unwrap();
println!("api resp: {}", resp.text().await.unwrap());
})
.await
}

#[tokio::test]
async fn new_timeseries() {
e2e_test_wrapper(async move {
let station_id = 40001;
let param_id = 145;

let client = reqwest::Client::new();
// 145, AGM, mean(air_gap PT10M)
// 146, AGX, max(air_gap PT10M)
let obsinn_msg = "kldata/nationalnr=40001/type=506/messageid=23
AGM(1,2),AGX(1,2)
20240606000000,11.0,12.0
20240606001000,12.0,19.0
20240606002000,10.0,16.0
20240606003000,12.0,16.0
20240606004000,11.0,15.0
";

// ingest data
let resp = client
.post("http://localhost:3001/kldata")
.body(obsinn_msg)
.send()
.await
.unwrap();

println!("\ningestor_resp: {}", resp.text().await.unwrap());

let url = format!(
"http://localhost:3000/stations/{}/params/{}",
station_id, param_id
);
let resp = client.get(url).send().await.unwrap();
println!("api_resp: {}", resp.text().await.unwrap());
// TODO: do something with the response
})
.await
}

0 comments on commit 2a51dc1

Please sign in to comment.