use serde_json::Value;
use super::*;
mod changes;
mod fixtures;
mod masking;
mod options;
mod secrets;
fn manifest(documents: &[&str]) -> Manifest {
Manifest::parse(&documents.iter().fold(String::new(), |text, document| {
format!("{text}---\n{document}\n")
}))
.expect("parses")
}
fn config_map(name: &str, data: &str) -> String {
format!("apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: {name}\ndata:\n key: {data}")
}
fn diff(before: &[&str], after: &[&str], options: &DiffOptions) -> Diff {
Diff::between(&manifest(before), &manifest(after), "shop", options).expect("diffs")
}
fn summary(diff: &Diff) -> Vec<(ChangeKind, String)> {
diff.changes
.iter()
.map(|change| (change.kind, change.id.to_string()))
.collect()
}
fn field_summary(change: &ObjectChange) -> Vec<(String, Option<Value>, Option<Value>)> {
change
.fields
.iter()
.map(|field| {
(
field.path.to_string(),
field.before.clone(),
field.after.clone(),
)
})
.collect()
}
type Case<'a> = (
&'a str,
&'a [&'a str],
&'a [&'a str],
Vec<(ChangeKind, &'a str)>,
);
fn check(table: Vec<Case<'_>>) {
for (name, before, after, expected) in table {
let expected: Vec<_> = expected
.into_iter()
.map(|(kind, key)| (kind, key.to_owned()))
.collect();
assert_eq!(
summary(&diff(before, after, &DiffOptions::default())),
expected,
"{name}"
);
}
}