Skip to content

Commit

Permalink
testing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
CHRISCARLON committed Oct 3, 2024
1 parent 3687dfc commit 761e597
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 67 deletions.
23 changes: 12 additions & 11 deletions src/duckdb_load/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,21 @@ pub fn load_file_duckdb(file_path: &str, file_type: &FileType) -> Result<()> {
}

// Process file
pub fn process_file(file_path: &str) -> Result<(), Box<dyn std::error::Error>> {
pub fn process_file(file_path: &str) -> io::Result<()> {
let mut file = File::open(file_path)?;
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;

match determine_file_type(&buffer) {
Ok(file_type) => {
println!("Detected file type: {:?}", file_type);
match load_file_duckdb(file_path, &file_type) {
Ok(_) => println!("Successfully loaded {:?} into DuckDB", file_type),
Err(e) => println!("Error loading {:?} into DuckDB: {}", file_type, e),
}
}
Err(e) => println!("Error determining file type: {}", e),
}
let file_type = determine_file_type(&buffer)?;
println!("Detected file type: {:?}", file_type);

load_file_duckdb(file_path, &file_type).map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("Error loading {:?} into DuckDB: {}", file_type, e),
)
})?;

println!("Successfully loaded {:?} into DuckDB", file_type);
Ok(())
}
16 changes: 8 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
mod duckdb_load;

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Hardcoded file path for demonstration
// In a real application, you might want to make this configurable
let file_path = "test_files/hotosm_twn_populated_places_points_geojson.geojson";

println!("Processing file: {}", file_path);

// Call the process_file function from the duckload module
match duckdb_load::process_file(file_path) {
Ok(_) => println!("File processed successfully."),
Err(e) => eprintln!("Error processing file: {}", e),
Ok(_) => {
println!("File processed successfully.");
Ok(())
}
Err(e) => {
eprintln!("Error processing file: {}", e);
Err(Box::new(e))
}
}

Ok(())
}
2 changes: 1 addition & 1 deletion test_files/invalid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
invalid file for testing
test file
65 changes: 18 additions & 47 deletions tests/duckdb_tests.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,25 @@
use duckdb_transformer::duckdb_load::process_file;
use std::path::Path;

const TEST_FILES_DIR: &str = "test_files";
#[cfg(test)]
mod tests {
use super::*;
use std::path::Path;

fn test_file_path(file_name: &str) -> String {
Path::new(TEST_FILES_DIR)
.join(file_name)
.to_str()
.unwrap()
.to_string()
}
#[test]
fn test_process_geojson_file() {
let file_path = "test_files/hotosm_twn_populated_places_points_geojson.geojson";

#[test]
fn test_process_invalid_file() {
let file_path = test_file_path("invalid.txt");
assert!(process_file(&file_path).is_err());
}
// Ensure the file exists
assert!(Path::new(file_path).exists(), "Test file does not exist");

#[test]
fn test_process_geojson() {
let file_path = test_file_path("hotosm_twn_populated_places_points_geojson.geojson");
assert!(process_file(&file_path).is_ok());
}
// Process the file
let result = process_file(file_path);

#[test]
fn test_process_geopackage() {
let file_path = test_file_path("GLA_High_Street_boundaries.gpkg");
assert!(process_file(&file_path).is_ok());
// Check if the processing was successful
assert!(
result.is_ok(),
"Failed to process the file: {:?}",
result.err()
);
}
}

// #[test]
// fn test_process_shapefile() {
// let file_path = test_file_path("your_shapefile.shp");
// assert!(process_file(&file_path).is_ok());
// }

// #[test]
// fn test_process_excel() {
// let file_path = test_file_path("your_excel_file.xlsx");
// assert!(process_file(&file_path).is_ok());
// }

// #[test]
// fn test_process_csv() {
// let file_path = test_file_path("your_csv_file.csv");
// assert!(process_file(&file_path).is_ok());
// }

// #[test]
// fn test_process_parquet() {
// let file_path = test_file_path("your_parquet_file.parquet");
// assert!(process_file(&file_path).is_ok());
// }

0 comments on commit 761e597

Please sign in to comment.