Added tests
All checks were successful
Rust Build / Check (pull_request) Successful in 1m4s
Rust Build / Test Suite (pull_request) Successful in 1m0s
Rust Build / Rustfmt (pull_request) Successful in 34s
Rust Build / Clippy (pull_request) Successful in 1m0s
Rust Build / build (pull_request) Successful in 58s

This commit is contained in:
2025-04-15 22:01:30 -04:00
parent 9a293cdb7f
commit c463bb3fb4

View File

@@ -377,8 +377,7 @@ mod tests {
let dir = String::from(util::TESTFILEDIRECTORY); let dir = String::from(util::TESTFILEDIRECTORY);
let temp_file = tempfile::tempdir().expect("Could not create test directory"); let temp_file = tempfile::tempdir().expect("Could not create test directory");
let mut test_dir = String::from(temp_file.path().to_str().unwrap()); let 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 test_filename = String::from("track08.flac");
let new_filepath = test_dir + "/" + &test_filename; let new_filepath = test_dir + "/" + &test_filename;
@@ -424,5 +423,367 @@ mod tests {
} }
}; };
} }
#[test]
fn test_set_artist() {
let filename = util::get_filename(1);
let dir = String::from(util::TESTFILEDIRECTORY);
let temp_file = tempfile::tempdir().expect("Could not create test directory");
let test_dir = String::from(temp_file.path().to_str().unwrap());
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::Artist, &filepath) {
Ok(artist) => {
let found = artist == "KD";
assert!(found, "Meta information was not found {:?}", artist);
let new_artist = String::from("Pilot");
match set_meta(types::Type::Artist, &new_filepath, &new_artist) {
Ok(m) => {
assert_eq!(
new_artist, m,
"New artist 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());
}
};
}
#[test]
fn test_set_album() {
let filename = util::get_filename(1);
let dir = String::from(util::TESTFILEDIRECTORY);
let temp_file = tempfile::tempdir().expect("Could not create test directory");
let test_dir = String::from(temp_file.path().to_str().unwrap());
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::Album, &filepath) {
Ok(title) => {
let found = title == "Sample Tracks 3";
assert!(found, "Meta information was not found {:?}", title);
let new_album = String::from("Sample Tracks 3 Remastered");
match set_meta(types::Type::Album, &new_filepath, &new_album) {
Ok(m) => {
assert_eq!(
new_album, m,
"New album 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());
}
};
}
#[test]
fn test_set_album_artist() {
let filename = util::get_filename(1);
let dir = String::from(util::TESTFILEDIRECTORY);
let temp_file = tempfile::tempdir().expect("Could not create test directory");
let test_dir = String::from(temp_file.path().to_str().unwrap());
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::AlbumArtist, &filepath) {
Ok(album_artist) => {
let found = album_artist == "KD";
assert!(found, "Meta information was not found {:?}", album_artist);
let new_album_artist = String::from("Bob");
match set_meta(
types::Type::AlbumArtist,
&new_filepath,
&new_album_artist,
) {
Ok(m) => {
assert_eq!(
new_album_artist, m,
"New album artist 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());
}
};
}
#[test]
fn test_set_date() {
let filename = util::get_filename(1);
let dir = String::from(util::TESTFILEDIRECTORY);
let temp_file = tempfile::tempdir().expect("Could not create test directory");
let test_dir = String::from(temp_file.path().to_str().unwrap());
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::Date, &filepath) {
Ok(date) => {
let found = date == "2025-04-11";
assert!(found, "Meta information was not found {:?}", date);
let new_date = String::from("2025-02-01");
match set_meta(types::Type::Date, &new_filepath, &new_date) {
Ok(m) => {
assert_eq!(new_date, m, "New date 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());
}
};
}
#[test]
fn test_set_track() {
let filename = util::get_filename(1);
let dir = String::from(util::TESTFILEDIRECTORY);
let temp_file = tempfile::tempdir().expect("Could not create test directory");
let test_dir = String::from(temp_file.path().to_str().unwrap());
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::Track, &filepath) {
Ok(track) => {
let found = track == "1";
assert!(found, "Meta information was not found {:?}", track);
let new_track = String::from("5");
match set_meta(types::Type::Track, &new_filepath, &new_track) {
Ok(m) => {
assert_eq!(
new_track, m,
"New track 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());
}
};
}
#[test]
fn test_set_disc() {
let filename = util::get_filename(1);
let dir = String::from(util::TESTFILEDIRECTORY);
let temp_file = tempfile::tempdir().expect("Could not create test directory");
let test_dir = String::from(temp_file.path().to_str().unwrap());
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::Disc, &filepath) {
Ok(disc) => {
let found = disc == "1";
assert!(found, "Meta information was not found {:?}", disc);
let new_disc = String::from("2");
match set_meta(types::Type::Disc, &new_filepath, &new_disc) {
Ok(m) => {
assert_eq!(new_disc, m, "New disc 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());
}
};
}
#[test]
fn test_set_genre() {
let filename = util::get_filename(1);
let dir = String::from(util::TESTFILEDIRECTORY);
let temp_file = tempfile::tempdir().expect("Could not create test directory");
let test_dir = String::from(temp_file.path().to_str().unwrap());
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::Genre, &filepath) {
Ok(genre) => {
let found = genre == "Metal";
assert!(found, "Meta information was not found {:?}", genre);
let new_genre = String::from("Blues");
match set_meta(types::Type::Genre, &new_filepath, &new_genre) {
Ok(m) => {
assert_eq!(
new_genre, m,
"New genre 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());
}
};
}
} }
} }