diff --git a/.gitignore b/.gitignore index 4aa11f8..b5e9a12 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ /web/dist /web/node_modules /web/wasm + +tests/fixtures/*.oas.json \ No newline at end of file diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index d7ed955..485e9da 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1,14 +1,35 @@ +use std::fs::File; +use std::io::prelude::*; + + macro_rules! test_fixture { ($name:ident, $filename:expr) => { #[test] fn $name() { let filename = get_fixture($filename); - let options = postman2openapi::TranspileOptions { - format: postman2openapi::TargetFormat::Json, - }; + let options = postman2openapi::TranspileOptions { + format: postman2openapi::TargetFormat::Json, + }; match postman2openapi::from_path(&filename, options) { - Ok(_oas) => assert!(true), - Err(err) => assert!(false, "{:?}", err), + Ok(_oas) => { + // Specify the target file path convert filename to filename_oas.json + let file_path = filename.replace("postman.json", "oas.json"); + + // Remove file if it exists + std::fs::remove_file(file_path.clone()).unwrap_or_default(); + + // Open or create the file + let mut file = File::create(file_path).expect("Failed to create file"); + + // Write data to the file + match file.write_all(_oas.as_bytes()) { + Ok(_) => assert!(true), + Err(err) => assert!(false, "{:?}", err), + } + }, + Err(err) => { + assert!(false, "{:?}", err); + }, } } };