Got it working
This commit is contained in:
75
src/meta.rs
75
src/meta.rs
@@ -119,6 +119,23 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn copy_file(
|
||||
source_path: &String,
|
||||
destination_path: &String,
|
||||
) -> Result<u64, std::io::Error> {
|
||||
println!("Copying file");
|
||||
let src_path = std::path::Path::new(source_path);
|
||||
let dest_path = std::path::Path::new(destination_path);
|
||||
|
||||
println!("Src: {:?}", src_path);
|
||||
println!("Dest: {:?}", dest_path);
|
||||
|
||||
match std::fs::copy(src_path, dest_path) {
|
||||
Ok(bytes) => Ok(bytes),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_exists(directory: &String, filename: &String) -> Result<bool, std::io::Error> {
|
||||
match path_buf(directory, filename) {
|
||||
Ok(pf) => Ok(pf.exists()),
|
||||
@@ -350,4 +367,62 @@ mod tests {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
mod set {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_set_title() {
|
||||
let filename = util::get_filename(1);
|
||||
let dir = String::from(util::TESTFILEDIRECTORY);
|
||||
|
||||
let temp_file = tempfile::tempdir().expect("Could not create test directory");
|
||||
let mut test_dir = String::from(temp_file.path().to_str().unwrap());
|
||||
// test_dir = String::from("tests/sample_tracks3");
|
||||
let test_filename = String::from("track08.flac");
|
||||
let new_filepath = test_dir + "/" + &test_filename;
|
||||
|
||||
match file_exists(&dir, &filename) {
|
||||
Ok(_) => {
|
||||
let filepath = get_full_path(&dir, &filename).unwrap();
|
||||
|
||||
match util::copy_file(&filepath, &new_filepath) {
|
||||
Ok(_o) => match get_meta(types::Type::Title, &filepath) {
|
||||
Ok(title) => {
|
||||
let found = title == "Just roll it";
|
||||
assert!(found, "Meta information was not found {:?}", title);
|
||||
let new_title = String::from("The wind burned her");
|
||||
|
||||
match set_meta(types::Type::Title, &new_filepath, &new_title) {
|
||||
Ok(m) => {
|
||||
assert_eq!(
|
||||
new_title, m,
|
||||
"New title does not match {:?}",
|
||||
m
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
assert!(
|
||||
false,
|
||||
"Error: {:?} source {:?} destination {:?}",
|
||||
err, filepath, new_filepath
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: File does not exist {:?}", err.to_string());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user