From dc57179ab469bfe7c2da5f93bbbdb09dd000e894 Mon Sep 17 00:00:00 2001 From: Manuel Carrer Date: Tue, 11 Jun 2024 16:44:17 +0200 Subject: [PATCH] Update lard_tests --- lard_tests/tests/api_integration_test.rs | 27 ++++++++++++++++++- lard_tests/tests/common/mod.rs | 17 ++++++++++-- .../tests/ingestion_integration_test.rs | 24 ++++------------- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/lard_tests/tests/api_integration_test.rs b/lard_tests/tests/api_integration_test.rs index d9f66601..9fa721d5 100644 --- a/lard_tests/tests/api_integration_test.rs +++ b/lard_tests/tests/api_integration_test.rs @@ -14,7 +14,7 @@ async fn api_test_wrapper>(test: T) { } #[tokio::test] -async fn test_stations_endpoint() { +async fn test_stations_endpoint_irregular() { api_test_wrapper(async { // NOTE: tseries.header.totime == Utc.now() let station_id = 18; @@ -36,6 +36,31 @@ async fn test_stations_endpoint() { .await } +// #[tokio::test] +// TODO: this generates a bunch of nulls +async fn test_stations_endpoint_regular() { + api_test_wrapper(async { + // NOTE: tseries.header.totime == Utc.now() + let station_id = 18; + let param_id = 103; + let query = "?time_resolution=P1D"; + + let url = format!( + "http://localhost:3000/stations/{}/params/{}{}", + station_id, param_id, query + ); + let resp = reqwest::get(url).await.unwrap(); + assert!(resp.status().is_success()); + + let json = resp.text().await.unwrap(); + println!("\n{}\n", json); + // assert_eq!(json, expected); + + // TODO: do something else with the response + }) + .await +} + #[tokio::test] async fn test_latest_endpoint() { api_test_wrapper(async { diff --git a/lard_tests/tests/common/mod.rs b/lard_tests/tests/common/mod.rs index 516c0ae1..4b223b69 100644 --- a/lard_tests/tests/common/mod.rs +++ b/lard_tests/tests/common/mod.rs @@ -9,10 +9,10 @@ use tokio::task::JoinHandle; use tokio_postgres::NoTls; use lard_ingestion::permissions::{ParamPermit, ParamPermitTable, StationPermitTable}; -use lard_ingestion::PgConnectionPool; +use lard_ingestion::{PgConnectionPool, PooledPgConn}; const CONNECT_STRING: &str = "host=localhost user=postgres dbname=postgres password=postgres"; -const PARAMCONV_CSV: &str = "../ingestion/resources/paramconversions.csv"; +pub const PARAMCONV_CSV: &str = "../ingestion/resources/paramconversions.csv"; pub async fn init_api_server() -> JoinHandle<()> { tokio::spawn(lard_api::run(CONNECT_STRING)) @@ -45,6 +45,19 @@ pub fn mock_permit_tables() -> Arc, ts_id: i32) -> usize { + let rows = conn + .query( + "SELECT * FROM public.data + WHERE timeseries = $1", + &[&ts_id], + ) + .await + .unwrap(); + + rows.len() +} + pub async fn init_ingestion_server( ) -> JoinHandle>> { tokio::spawn(lard_ingestion::run( diff --git a/lard_tests/tests/ingestion_integration_test.rs b/lard_tests/tests/ingestion_integration_test.rs index d2511e0f..0299346c 100644 --- a/lard_tests/tests/ingestion_integration_test.rs +++ b/lard_tests/tests/ingestion_integration_test.rs @@ -1,32 +1,18 @@ use chrono::{TimeZone, Utc}; use test_case::test_case; -use common::{init_db_pool, mock_permit_tables}; -use lard_ingestion::{insert_data, permissions::timeseries_is_open, Data, Datum, PooledPgConn}; +use lard_ingestion::{insert_data, permissions::timeseries_is_open, Data, Datum}; pub mod common; -async fn get_number_of_rows(conn: &PooledPgConn<'_>, id: i32) -> usize { - let rows = conn - .query( - "SELECT * FROM public.data - WHERE timeseries = $1", - &[&id], - ) - .await - .unwrap(); - - rows.len() -} - #[tokio::test] async fn test_insert_data() { - let pool = init_db_pool().await.unwrap(); + let pool = common::init_db_pool().await.unwrap(); let mut conn = pool.get().await.unwrap(); // Timeseries ID 2 has hourly data let id: i32 = 2; - let count_before_insertion = get_number_of_rows(&conn, id).await; + let count_before_insertion = common::number_of_data_rows(&conn, id).await; let data: Data = (1..10) .map(|i| { @@ -38,7 +24,7 @@ async fn test_insert_data() { insert_data(data, &mut conn).await.unwrap(); - let count_after_insertion = get_number_of_rows(&conn, id).await; + let count_after_insertion = common::number_of_data_rows(&conn, id).await; let rows_inserted = count_after_insertion - count_before_insertion; // This makes sure the assert doesn't fail locally if the database hasn't been cleaned up between runs @@ -53,7 +39,7 @@ async fn test_insert_data() { #[test_case(4, 0, 1 => true; "stationid in StationPermitTable, timeseries open")] #[test_case(2, 0, 0 => true; "stationid in ParamPermitTable, timeseries open")] fn test_timeseries_is_open(station_id: i32, type_id: i32, permit_id: i32) -> bool { - let permit_tables = mock_permit_tables(); + let permit_tables = common::mock_permit_tables(); timeseries_is_open(permit_tables, station_id, type_id, permit_id).unwrap() }