Skip to content

Commit 9106ef4

Browse files
committed
f Use random path for SqliteStore tests
1 parent 4a616e3 commit 9106ef4

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/io/sqlite_store/migrations.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub(super) fn migrate_schema(
3737
mod tests {
3838
use crate::io::sqlite_store::SqliteStore;
3939
use crate::io::test_utils::do_read_write_remove_list_persist;
40+
use crate::test::utils::random_storage_path;
4041

4142
use lightning::util::persist::KVStore;
4243

@@ -48,7 +49,7 @@ mod tests {
4849
fn rwrl_post_schema_1_migration() {
4950
let old_schema_version = 1;
5051

51-
let mut temp_path = std::env::temp_dir();
52+
let mut temp_path = random_storage_path();
5253
temp_path.push("rwrl_post_schema_1_migration");
5354

5455
let db_file_name = "test_db".to_string();

src/io/sqlite_store/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ impl KVStore for SqliteStore {
281281
mod tests {
282282
use super::*;
283283
use crate::io::test_utils::{do_read_write_remove_list_persist, do_test_store};
284+
use crate::test::utils::random_storage_path;
284285

285286
impl Drop for SqliteStore {
286287
fn drop(&mut self) {
@@ -293,7 +294,7 @@ mod tests {
293294

294295
#[test]
295296
fn read_write_remove_list_persist() {
296-
let mut temp_path = std::env::temp_dir();
297+
let mut temp_path = random_storage_path();
297298
temp_path.push("read_write_remove_list_persist");
298299
let store = SqliteStore::new(
299300
temp_path,
@@ -306,7 +307,7 @@ mod tests {
306307

307308
#[test]
308309
fn test_sqlite_store() {
309-
let mut temp_path = std::env::temp_dir();
310+
let mut temp_path = random_storage_path();
310311
temp_path.push("test_sqlite_store");
311312
let store_0 = SqliteStore::new(
312313
temp_path.clone(),

src/test/utils.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::collections::hash_map;
2020
use std::collections::HashMap;
2121
use std::env;
2222
use std::io::{self, Write};
23+
use std::path::PathBuf;
2324
use std::sync::atomic::{AtomicBool, Ordering};
2425
use std::sync::Arc;
2526
use std::sync::Mutex;
@@ -220,10 +221,12 @@ impl Logger for TestLogger {
220221
}
221222
}
222223

223-
pub fn random_storage_path() -> String {
224+
pub fn random_storage_path() -> PathBuf {
225+
let mut temp_path = std::env::temp_dir();
224226
let mut rng = thread_rng();
225227
let rand_dir: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
226-
format!("/tmp/{}", rand_dir)
228+
temp_path.push(rand_dir);
229+
temp_path
227230
}
228231

229232
pub fn random_port() -> u16 {
@@ -238,8 +241,8 @@ pub fn random_config() -> Config {
238241
println!("Setting network: {}", config.network);
239242

240243
let rand_dir = random_storage_path();
241-
println!("Setting random LDK storage dir: {}", rand_dir);
242-
config.storage_dir_path = rand_dir;
244+
println!("Setting random LDK storage dir: {}", rand_dir.display());
245+
config.storage_dir_path = rand_dir.to_str().unwrap().to_owned();
243246

244247
let rand_port = random_port();
245248
println!("Setting random LDK listening port: {}", rand_port);

0 commit comments

Comments
 (0)