Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ sha2 = "0.10.8"

[dev-dependencies]
tempfile = "3.14.0"
tmp-path = "0.1.0"
71 changes: 29 additions & 42 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,21 @@ fn main() {
mod tests {
use super::*;
use tempfile::tempdir;
use tmp_path::tmp_path;

#[tmp_path]
fn fake_file_path() -> PathBuf {
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let file_path = base.join("test.txt");
let file_path = tmp_path.join("test.txt");

let mut file = File::create(&file_path).unwrap();
file.write_all(b"This is a test").unwrap();

file_path
}

#[tmp_path]
fn fake_file_path_2() -> PathBuf {
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let file_path = base.join("test2.txt");
let file_path = tmp_path.join("test2.txt");

let mut file = File::create(&file_path).unwrap();
file.write_all(b"This is another test").unwrap();
Expand Down Expand Up @@ -269,11 +268,10 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_md5_file() {
let test_file = fake_file_path();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file,
Expand All @@ -293,12 +291,11 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_md5_file_directory_overwrite() {
let test_file_1 = fake_file_path();
let test_file_2 = fake_file_path_2();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file_1,
Expand Down Expand Up @@ -335,12 +332,11 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_md5_file_directory_no_overwrite() {
let test_file_1 = fake_file_path();
let test_file_2 = fake_file_path_2();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file_1,
Expand Down Expand Up @@ -371,11 +367,10 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_sha256_file() {
let test_file = fake_file_path();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file,
Expand All @@ -395,12 +390,11 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_sha256_file_directory_overwrite() {
let test_file_1 = fake_file_path();
let test_file_2 = fake_file_path_2();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file_1,
Expand Down Expand Up @@ -437,12 +431,11 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_sha256_file_directory_no_overwrite() {
let test_file_1 = fake_file_path();
let test_file_2 = fake_file_path_2();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file_1,
Expand Down Expand Up @@ -473,11 +466,10 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_sha512() {
let test_file = fake_file_path();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file,
Expand All @@ -497,12 +489,11 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_sha512_file_directory_overwrite() {
let test_file_1 = fake_file_path();
let test_file_2 = fake_file_path_2();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file_1,
Expand Down Expand Up @@ -539,12 +530,11 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_sha512_file_directory_no_overwrite() {
let test_file_1 = fake_file_path();
let test_file_2 = fake_file_path_2();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file_1,
Expand Down Expand Up @@ -575,11 +565,10 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_sha1_file() {
let test_file = fake_file_path();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file,
Expand All @@ -599,12 +588,11 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_sha1_file_directory_overwrite() {
let test_file_1 = fake_file_path();
let test_file_2 = fake_file_path_2();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file_1,
Expand Down Expand Up @@ -641,12 +629,11 @@ mod tests {
}

#[test]
#[tmp_path]
fn generate_sha1_file_directory_no_overwrite() {
let test_file_1 = fake_file_path();
let test_file_2 = fake_file_path_2();
let base = tempdir().unwrap().path().to_path_buf();
fs::create_dir_all(&base).unwrap();
let output_file = base.join("output.txt");
let output_file = tmp_path.join("output.txt");

process_checksum(
&test_file_1,
Expand Down
Loading