Skip to content

Commit 23011fe

Browse files
authored
Merge pull request #88 from lovasoa/integration-tests
add integration tests for all supported databases
2 parents 8c38c6d + 67573e7 commit 23011fe

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

.github/workflows/tests.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,28 @@ env:
1717
CARGO_TERM_COLOR: always
1818

1919
jobs:
20-
tests:
20+
compile_and_lint:
2121
runs-on: ubuntu-latest
2222
steps:
2323
- uses: actions/checkout@v3
2424
- name: Set up cargo cache
2525
uses: Swatinem/rust-cache@dd05243424bd5c0e585e4b55eb2d7615cdd32f1f
2626
- run: cargo fmt --all -- --check
2727
- run: cargo clippy
28-
- run: cargo test
2928
- run: cargo test --all-features
29+
- run: cargo test
30+
31+
test:
32+
needs: compile_and_lint
33+
runs-on: ubuntu-latest
34+
strategy:
35+
matrix:
36+
database: ['postgres', 'mysql', 'mssql']
37+
steps:
38+
- uses: actions/checkout@v3
39+
- name: Start database container
40+
run: docker-compose up -d ${{ matrix.database }}
41+
- name: Run tests against ${{ matrix.database }}
42+
run: cargo test
43+
env:
44+
DATABASE_URL: ${{ matrix.database }}://root:[email protected]/sqlpage

tests/index.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ use sqlpage::{app_config::AppConfig, webserver::http::main_handler, AppState};
66

77
#[actix_web::test]
88
async fn test_index_ok() {
9+
init_log();
910
let config = test_config();
1011
let state = AppState::init(&config).await.unwrap();
1112
let data = actix_web::web::Data::new(state);
12-
let req = test::TestRequest::default()
13+
let req = test::TestRequest::get()
14+
.uri("/")
1315
.app_data(data)
1416
.insert_header(ContentType::plaintext())
1517
.to_srv_request();
@@ -24,11 +26,19 @@ async fn test_index_ok() {
2426
}
2527

2628
pub fn test_config() -> AppConfig {
27-
serde_json::from_str::<AppConfig>(
28-
r#"{
29-
"database_url": "sqlite::memory:",
29+
let db_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite::memory:".to_string());
30+
serde_json::from_str::<AppConfig>(&format!(
31+
r#"{{
32+
"database_url": "{}",
33+
"database_connection_retries": 2,
34+
"database_connection_acquire_timeout_seconds": 1,
3035
"listen_on": "111.111.111.111:1"
31-
}"#,
32-
)
36+
}}"#,
37+
db_url
38+
))
3339
.unwrap()
3440
}
41+
42+
fn init_log() {
43+
env_logger::builder().is_test(true).try_init().unwrap();
44+
}

0 commit comments

Comments
 (0)