use anyhow::{Context, Result};
use std::{
env,
fs::{create_dir_all, remove_dir_all},
path::PathBuf,
};
#[allow(unused)]
pub(crate) const LOCAL_REGISTRY: &str = "localhost:5001";
#[allow(unused)]
pub(crate) fn wash() -> std::process::Command {
test_bin::get_test_bin("wash")
}
#[allow(unused)]
pub(crate) fn output_to_string(output: std::process::Output) -> Result<String> {
String::from_utf8(output.stdout).with_context(|| "Failed to convert output bytes to String")
}
#[allow(unused)]
pub(crate) fn get_json_output(output: std::process::Output) -> Result<serde_json::Value> {
let output_str = output_to_string(output)?;
let json: serde_json::Value = serde_json::from_str(&output_str)
.with_context(|| "Failed to parse json from output string")?;
Ok(json)
}
#[allow(unused)]
pub(crate) fn test_dir_with_subfolder(subfolder: &str) -> PathBuf {
let root_dir = &env::var("CARGO_MANIFEST_DIR").expect("$CARGO_MANIFEST_DIR");
let with_subfolder = PathBuf::from(format!("{root_dir}/tests/fixtures/{subfolder}"));
remove_dir_all(with_subfolder.clone());
create_dir_all(with_subfolder.clone());
with_subfolder
}
#[allow(unused)]
pub(crate) fn test_dir_file(subfolder: &str, file: &str) -> PathBuf {
let root_dir = &env::var("CARGO_MANIFEST_DIR").expect("$CARGO_MANIFEST_DIR");
PathBuf::from(format!("{root_dir}/tests/fixtures/{subfolder}/{file}"))
}