pub mod errors;
pub mod registry_writer;
pub mod types;
pub mod verifiers;
pub mod yaml_writer;
#[cfg(feature = "http-proxy")]
pub mod http_proxy_writer;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OutputFormat {
Yaml,
Registry,
HttpProxy,
}
pub fn get_writer(format: &str) -> Option<OutputFormat> {
match format.to_ascii_lowercase().as_str() {
"yaml" => Some(OutputFormat::Yaml),
"registry" => Some(OutputFormat::Registry),
"http_proxy" | "http-proxy" | "httpproxy" => Some(OutputFormat::HttpProxy),
_ => None,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_writer_yaml() {
assert_eq!(get_writer("yaml"), Some(OutputFormat::Yaml));
}
#[test]
fn test_get_writer_registry() {
assert_eq!(get_writer("registry"), Some(OutputFormat::Registry));
}
#[test]
fn test_get_writer_http_proxy_variants() {
assert_eq!(get_writer("http_proxy"), Some(OutputFormat::HttpProxy));
assert_eq!(get_writer("http-proxy"), Some(OutputFormat::HttpProxy));
assert_eq!(get_writer("httpproxy"), Some(OutputFormat::HttpProxy));
}
#[test]
fn test_get_writer_case_insensitive() {
assert_eq!(get_writer("YAML"), Some(OutputFormat::Yaml));
assert_eq!(get_writer("Registry"), Some(OutputFormat::Registry));
assert_eq!(get_writer("HTTP_PROXY"), Some(OutputFormat::HttpProxy));
}
#[test]
fn test_get_writer_unknown() {
assert_eq!(get_writer("xml"), None);
assert_eq!(get_writer(""), None);
}
#[test]
fn test_output_format_serde_roundtrip() {
let fmt = OutputFormat::Yaml;
let json = serde_json::to_string(&fmt).unwrap();
let deserialized: OutputFormat = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized, fmt);
}
}