Skip to content

Commit

Permalink
Fixed bug in sdf mv that occurred in addressing issue #14.
Browse files Browse the repository at this point in the history
 - New `test_mv()` function to test mv and catch future bugs.
 - Fixed the bug, in which the wrong variable was used.
  • Loading branch information
vsbuffalo committed Feb 22, 2024
1 parent 2c47bb7 commit ee21983
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scidataflow"
version = "0.8.8"
version = "0.8.9"
edition = "2021"
exclude = ["logo.png", "tests/test_data/**"]
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ impl Project {
}

// move the actual file
rename(source, destination_path).context("Error encountered when moving file.")?;
rename(source, &destination_path).context("Error encountered when moving file.")?;

// update the relative path
let relative_destination = self.relative_path_string(Path::new(destination))?;
let relative_destination = self.relative_path_string(destination_path.as_path())?;

// modify the DataFile
let mut new_file = file.clone();
Expand Down
48 changes: 48 additions & 0 deletions tests/test_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod tests {
use super::get_statuses;
use super::setup;
use scidataflow::lib::data::LocalStatusCode;
use std::fs;
use std::path::PathBuf;

#[tokio::test]
Expand Down Expand Up @@ -160,4 +161,51 @@ mod tests {
}
}
}

#[tokio::test]
async fn test_mv() {
let mut fixture = setup(false).await;
let path_context = fixture.project.path_context();
let statuses = get_statuses(&mut fixture, &path_context).await;

// at this point the status should be empty
assert!(statuses.is_empty());

// get the files to add
let files = &fixture.env.files.as_ref().unwrap();
let add_files: Vec<String> = files
.into_iter()
.filter(|f| f.add)
.map(|f| f.path.clone())
.collect();

// add those files
let _ = fixture.project.add(&add_files).await;

let new_name = "data/data_alt.tsv";
let target_path = PathBuf::from(new_name);

let statuses = get_statuses(&mut fixture, &path_context).await;
let exists = statuses.iter().any(|(path, _status)| path == &target_path);
assert!(!exists); // not there before move

// try moving a file (renaming)
fixture.project.mv("data/data.tsv", new_name).await.unwrap();

let exists = statuses.iter().any(|(path, _status)| path == &target_path);
assert!(!exists); // now it should be there

// now let's try moving to a directory
fs::create_dir_all("new_data/").unwrap();
fixture
.project
.mv("data/supplement/big_1.tsv.gz", "new_data/")
.await
.unwrap();

let statuses = get_statuses(&mut fixture, &path_context).await;
let target_path = PathBuf::from("data/supplement/big_1.tsv.gz");
let exists = statuses.iter().any(|(path, _status)| path == &target_path);
assert!(!exists); // now it should be there
}
}

0 comments on commit ee21983

Please sign in to comment.