diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 27394e7e..a99ab062 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,6 +13,17 @@ jobs: build: runs-on: ubuntu-latest + services: + postgres: + image: postgres:15.3 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: moksha-mint + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + steps: - uses: actions/checkout@v3 - name: Install protobuf-compiler @@ -20,7 +31,7 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose + run: cargo test --features integration-tests --verbose coverage: runs-on: ubuntu-latest name: coverage diff --git a/integrationtests/Cargo.toml b/integrationtests/Cargo.toml index 0bfe1ca3..a2e0db51 100644 --- a/integrationtests/Cargo.toml +++ b/integrationtests/Cargo.toml @@ -17,6 +17,9 @@ path = "tests/tests.rs" name = "lnbitsmock" path = "src/lnbitsmock.rs" +[features] +integration-tests = [] + [dependencies] rand = "0.8.5" axum = "0.6.20" diff --git a/integrationtests/tests/tests.rs b/integrationtests/tests/tests.rs index f0e1e745..32721d80 100644 --- a/integrationtests/tests/tests.rs +++ b/integrationtests/tests/tests.rs @@ -1,3 +1,4 @@ +#![allow(unused_imports)] use moksha_wallet::client::reqwest::HttpClient; use moksha_wallet::client::LegacyClient; use moksha_wallet::localstore::sqlite::SqliteLocalStore; @@ -10,9 +11,8 @@ use std::time::Duration; use tokio::runtime::Runtime; use tokio::time::{sleep_until, Instant}; -// FIXME integration-test don't work anymore, because postgres is not available #[test] -#[ignore] +#[cfg(feature = "integration-tests")] pub fn test_integration() -> anyhow::Result<()> { // start lnbits let _lnbits_thread = thread::spawn(|| { @@ -26,12 +26,9 @@ pub fn test_integration() -> anyhow::Result<()> { let _server_thread = thread::spawn(|| { let rt = tokio::runtime::Runtime::new().expect("Failed to create Tokio runtime"); rt.block_on(async { - let tmp = tempfile::tempdir().expect("Could not create tmp dir"); - let tmp_dir = tmp.path().to_str().expect("Could not create tmp dir"); - let mint = Mint::builder() .with_private_key("my_private_key".to_string()) - .with_db(tmp_dir.to_string()) // FIXME use in-memory db? + .with_db("postgres://postgres:postgres@127.0.0.1/moksha-mint".to_owned()) .with_lightning(LightningType::Lnbits(LnbitsLightningSettings::new( "my_admin_key", "http://127.0.0.1:6100", @@ -46,7 +43,6 @@ pub fn test_integration() -> anyhow::Result<()> { None, ) .await; - drop(tmp); assert!(result.is_ok()); }); }); @@ -128,6 +124,7 @@ pub fn test_integration() -> anyhow::Result<()> { Ok(()) } +#[cfg(feature = "integration-tests")] fn read_fixture(name: &str) -> anyhow::Result { let base_dir = std::env::var("CARGO_MANIFEST_DIR")?; let raw_token = std::fs::read_to_string(format!("{base_dir}/tests/fixtures/{name}"))?;