Remove dead code.

This commit is contained in:
jcamiel 2023-02-09 22:09:38 +01:00
parent 9b4664d9a9
commit d9fb8e7576
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
2 changed files with 5 additions and 47 deletions

View File

@ -16,52 +16,5 @@
* *
*/ */
use crate::cli::CliError;
use std::io::prelude::*;
use std::path::PathBuf;
mod result; mod result;
mod value; mod value;
pub fn write_json_report(
file_path: PathBuf,
results: Vec<serde_json::Value>,
) -> Result<(), CliError> {
let mut file = match std::fs::File::create(&file_path) {
Err(why) => {
return Err(CliError {
message: format!("Issue writing to {}: {:?}", file_path.display(), why),
})
}
Ok(file) => file,
};
let serialized = serde_json::to_string_pretty(&results).unwrap();
if let Err(why) = file.write_all(serialized.as_bytes()) {
Err(CliError {
message: format!("Issue writing to {}: {:?}", file_path.display(), why),
})
} else {
Ok(())
}
}
pub fn parse_json(path: PathBuf) -> Result<Vec<serde_json::Value>, CliError> {
if path.exists() {
let s = match std::fs::read_to_string(path.clone()) {
Ok(s) => s,
Err(why) => {
return Err(CliError {
message: format!("Issue reading {} to string to {:?}", path.display(), why),
});
}
};
match serde_json::from_str(s.as_str()) {
Ok(val) => Ok(val),
Err(_) => Err(CliError {
message: format!("The file {} is not a valid json file", path.display()),
}),
}
} else {
Ok(vec![])
}
}

View File

@ -23,6 +23,11 @@ use crate::http::{
use crate::runner::{AssertResult, Call, CaptureResult, EntryResult, HurlResult}; use crate::runner::{AssertResult, Call, CaptureResult, EntryResult, HurlResult};
impl HurlResult { impl HurlResult {
/// Serializes an [`HurlResult`] to a JSON representation.
///
/// Note: `content` is passed to this method to save asserts and
/// errors messages (with lines and columns). This parameter will be removed
/// soon and the original content will be accessible through the [`HurlResult`] instance.
pub fn to_json(&self, content: &str) -> serde_json::Value { pub fn to_json(&self, content: &str) -> serde_json::Value {
let mut map = serde_json::Map::new(); let mut map = serde_json::Map::new();
map.insert( map.insert(