arg: fix broken dbpath argument, add test
I broke dbpath, lets fix that and add a test so it doesn't happen again Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -392,10 +392,11 @@ impl Damus {
|
|||||||
.datapath
|
.datapath
|
||||||
.unwrap_or(data_path.as_ref().to_str().expect("db path ok").to_string());
|
.unwrap_or(data_path.as_ref().to_str().expect("db path ok").to_string());
|
||||||
let path = DataPath::new(&data_path);
|
let path = DataPath::new(&data_path);
|
||||||
let dbpath_ = path.path(DataPathType::Db);
|
let dbpath_str = parsed_args
|
||||||
let dbpath = dbpath_.to_str().unwrap();
|
.dbpath
|
||||||
|
.unwrap_or_else(|| path.path(DataPathType::Db).to_str().unwrap().to_string());
|
||||||
|
|
||||||
let _ = std::fs::create_dir_all(dbpath);
|
let _ = std::fs::create_dir_all(&dbpath_str);
|
||||||
|
|
||||||
let imgcache_dir = path.path(DataPathType::Cache).join(ImageCache::rel_dir());
|
let imgcache_dir = path.path(DataPathType::Cache).join(ImageCache::rel_dir());
|
||||||
let _ = std::fs::create_dir_all(imgcache_dir.clone());
|
let _ = std::fs::create_dir_all(imgcache_dir.clone());
|
||||||
@@ -453,7 +454,7 @@ impl Damus {
|
|||||||
.get_selected_account()
|
.get_selected_account()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|a| a.pubkey.bytes());
|
.map(|a| a.pubkey.bytes());
|
||||||
let ndb = Ndb::new(dbpath, &config).expect("ndb");
|
let ndb = Ndb::new(&dbpath_str, &config).expect("ndb");
|
||||||
|
|
||||||
let mut columns = if parsed_args.columns.is_empty() {
|
let mut columns = if parsed_args.columns.is_empty() {
|
||||||
if let Some(serializable_columns) = storage::load_columns(&path) {
|
if let Some(serializable_columns) = storage::load_columns(&path) {
|
||||||
|
|||||||
26
src/args.rs
26
src/args.rs
@@ -265,6 +265,32 @@ mod tests {
|
|||||||
std::fs::remove_dir_all(path);
|
std::fs::remove_dir_all(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ensure dbpath actually sets the dbpath correctly.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_dbpath() {
|
||||||
|
let datapath = create_tmp_dir();
|
||||||
|
let dbpath = create_tmp_dir();
|
||||||
|
let args = vec![
|
||||||
|
"--datapath",
|
||||||
|
&datapath.to_str().unwrap(),
|
||||||
|
"--dbpath",
|
||||||
|
&dbpath.to_str().unwrap(),
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let ctx = egui::Context::default();
|
||||||
|
let app = Damus::new(&ctx, &datapath, args);
|
||||||
|
|
||||||
|
assert!(Path::new(&dbpath.join("data.mdb")).exists());
|
||||||
|
assert!(Path::new(&dbpath.join("lock.mdb")).exists());
|
||||||
|
assert!(!Path::new(&datapath.join("db")).exists());
|
||||||
|
|
||||||
|
rmrf(datapath);
|
||||||
|
rmrf(dbpath);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_column_args() {
|
async fn test_column_args() {
|
||||||
let tmpdir = create_tmp_dir();
|
let tmpdir = create_tmp_dir();
|
||||||
|
|||||||
Reference in New Issue
Block a user