Skip to content

Commit

Permalink
fix: run integratintests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Dec 18, 2023
1 parent 132b955 commit 59bd23c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@ 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
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- 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
Expand Down
3 changes: 3 additions & 0 deletions integrationtests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 4 additions & 7 deletions integrationtests/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unused_imports)]
use moksha_wallet::client::reqwest::HttpClient;
use moksha_wallet::client::LegacyClient;
use moksha_wallet::localstore::sqlite::SqliteLocalStore;
Expand All @@ -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(|| {
Expand All @@ -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:[email protected]/moksha-mint".to_owned())
.with_lightning(LightningType::Lnbits(LnbitsLightningSettings::new(
"my_admin_key",
"http://127.0.0.1:6100",
Expand All @@ -46,7 +43,6 @@ pub fn test_integration() -> anyhow::Result<()> {
None,
)
.await;
drop(tmp);
assert!(result.is_ok());
});
});
Expand Down Expand Up @@ -128,6 +124,7 @@ pub fn test_integration() -> anyhow::Result<()> {
Ok(())
}

#[cfg(feature = "integration-tests")]
fn read_fixture(name: &str) -> anyhow::Result<String> {
let base_dir = std::env::var("CARGO_MANIFEST_DIR")?;
let raw_token = std::fs::read_to_string(format!("{base_dir}/tests/fixtures/{name}"))?;
Expand Down

0 comments on commit 59bd23c

Please sign in to comment.