-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(libmake): ✅ add tests for
csv.rs
- Loading branch information
1 parent
d0d2b39
commit 07ce546
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use libmake::generators::csv::generate_from_csv; | ||
use std::fs::File; | ||
use std::io::Write; | ||
|
||
#[test] | ||
fn test_generate_from_csv_valid() { | ||
// Create a temporary CSV file | ||
let csv_content = "\ | ||
author,build,categories,description,documentation,edition,email,homepage,keywords,license,name,output,readme,repository,rustversion,version,website\n\ | ||
John Doe,cargo build,web,Sample project,,2021,[email protected],https://example.com,example,Rust-1.0,SampleProject,/tmp/output,README.md,https://github.com/example,1.51.0,0.1.0,https://example.com\n"; | ||
|
||
let path = "/tmp/test_valid.csv"; | ||
let mut file = File::create(path).unwrap(); | ||
file.write_all(csv_content.as_bytes()).unwrap(); | ||
|
||
// Call the function and check for success | ||
let result = generate_from_csv(path); | ||
assert!(result.is_ok()); | ||
|
||
// Clean up | ||
std::fs::remove_file(path).unwrap(); | ||
} | ||
|
||
#[test] | ||
fn test_generate_from_csv_invalid_path() { | ||
let result = generate_from_csv("/invalid/path/to/csv"); | ||
assert!(result.is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_generate_from_csv_malformed_csv() { | ||
// Create a temporary malformed CSV file | ||
let csv_content = "author,build,categories,description,documentation,edition,email,homepage,keywords,license,name,output,readme,repository,rustversion,version,website\n\ | ||
John Doe,cargo build,web,Sample project,,2021,[email protected],https://example.com,example,Rust-1.0,SampleProject,/tmp/output,README.md,https://github.com/example,1.51.0,0.1.0"; | ||
|
||
let path = "/tmp/test_malformed.csv"; | ||
let mut file = File::create(path).unwrap(); | ||
file.write_all(csv_content.as_bytes()).unwrap(); | ||
|
||
// Call the function and check for error | ||
let result = generate_from_csv(path); | ||
assert!(result.is_err()); | ||
|
||
// Clean up | ||
std::fs::remove_file(path).unwrap(); | ||
} | ||
} |