Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,28 @@ env:
CARGO_TERM_COLOR: always

jobs:
tests:
compile_and_lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up cargo cache
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
22 changes: 16 additions & 6 deletions tests/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -24,11 +26,19 @@ async fn test_index_ok() {
}

pub fn test_config() -> AppConfig {
serde_json::from_str::<AppConfig>(
r#"{
"database_url": "sqlite::memory:",
let db_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite::memory:".to_string());
serde_json::from_str::<AppConfig>(&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();
}