From 7885a2c28bbf23f8f8d98dc9d212335c8dac8954 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sun, 17 Sep 2023 21:26:15 +0200 Subject: [PATCH] add integration tests for all supported databases --- .github/workflows/tests.yml | 19 +++++++++++++++++-- tests/index.rs | 22 ++++++++++++++++------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ca5fd74d..48f495f8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,7 +17,7 @@ env: CARGO_TERM_COLOR: always jobs: - tests: + compile_and_lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -25,5 +25,20 @@ jobs: uses: Swatinem/rust-cache@dd05243424bd5c0e585e4b55eb2d7615cdd32f1f - run: cargo fmt --all -- --check - run: cargo clippy - - run: cargo test - run: cargo test --all-features + - run: cargo test + + test: + needs: compile_and_lint + runs-on: ubuntu-latest + strategy: + matrix: + database: ['postgres', 'mysql', 'mssql'] + steps: + - uses: actions/checkout@v3 + - name: Start database container + run: docker-compose up -d ${{ matrix.database }} + - name: Run tests against ${{ matrix.database }} + run: cargo test + env: + DATABASE_URL: ${{ matrix.database }}://root:Password123!@127.0.0.1/sqlpage diff --git a/tests/index.rs b/tests/index.rs index 19bf2ec9..1089abcb 100644 --- a/tests/index.rs +++ b/tests/index.rs @@ -6,10 +6,12 @@ use sqlpage::{app_config::AppConfig, webserver::http::main_handler, AppState}; #[actix_web::test] async fn test_index_ok() { + init_log(); let config = test_config(); let state = AppState::init(&config).await.unwrap(); let data = actix_web::web::Data::new(state); - let req = test::TestRequest::default() + let req = test::TestRequest::get() + .uri("/") .app_data(data) .insert_header(ContentType::plaintext()) .to_srv_request(); @@ -24,11 +26,19 @@ async fn test_index_ok() { } pub fn test_config() -> AppConfig { - serde_json::from_str::( - r#"{ - "database_url": "sqlite::memory:", + let db_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite::memory:".to_string()); + serde_json::from_str::(&format!( + r#"{{ + "database_url": "{}", + "database_connection_retries": 2, + "database_connection_acquire_timeout_seconds": 1, "listen_on": "111.111.111.111:1" - }"#, - ) + }}"#, + db_url + )) .unwrap() } + +fn init_log() { + env_logger::builder().is_test(true).try_init().unwrap(); +}