-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fix issues discovered by validation
- Loading branch information
Showing
19 changed files
with
346 additions
and
81 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::collections::BTreeMap; // BTreeMap sorts by key, HashMap doesn't | ||
use std::fmt; | ||
|
||
use super::validator::ValidatorCode; | ||
use super::VALIDATORS; | ||
|
||
const WIDTH: usize = 70; | ||
|
||
#[derive(Default)] | ||
pub struct ValidationSummary { | ||
pub annotations: BTreeMap<ValidatorCode, usize>, | ||
pub patches: usize, | ||
} | ||
|
||
impl fmt::Display for ValidationSummary { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
writeln!(f, "\nValidation errors found:")?; | ||
writeln!(f, "{}", "-".repeat(WIDTH))?; | ||
for (code, count) in self.annotations.iter() { | ||
if *count == 0 { | ||
continue; | ||
} | ||
let name = VALIDATORS.lookup(code).map(|v| v.name).unwrap_or("<unknown>"); | ||
let left = format!("{name} ({code})"); | ||
let right = format!("{count}"); | ||
let mid_width = WIDTH.saturating_sub(left.len()).saturating_sub(right.len()).saturating_sub(2); // two chars for extra spaces | ||
writeln!(f, "{left} {} {right}", ".".repeat(mid_width))?; | ||
} | ||
|
||
if self.patches > 0 { | ||
writeln!(f, "{}", "-".repeat(WIDTH))?; | ||
writeln!(f, "Patches applied: {}", self.patches)?; | ||
writeln!(f, "0 problems remaining")?; | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use assertables::*; | ||
use json_patch_ext::prelude::*; | ||
|
||
use super::*; | ||
|
||
#[rstest] | ||
fn test_apply_patch_everywhere(mut annotated_trace: AnnotatedTrace) { | ||
annotated_trace | ||
.apply_patch(AnnotatedTracePatch { | ||
locations: PatchLocations::Everywhere, | ||
op: add_operation(format_ptr!("/foo"), "bar".into()), | ||
}) | ||
.unwrap(); | ||
|
||
for event in annotated_trace.iter() { | ||
for obj in event.data.applied_objs.iter().chain(event.data.deleted_objs.iter()) { | ||
assert_eq!(obj.data.get("foo").unwrap(), "bar"); | ||
} | ||
} | ||
} | ||
|
||
#[rstest] | ||
fn test_apply_patch_object_reference(mut annotated_trace: AnnotatedTrace) { | ||
annotated_trace | ||
.apply_patch(AnnotatedTracePatch { | ||
locations: PatchLocations::ObjectReference( | ||
DEPL_GVK.into_type_meta(), | ||
format!("{TEST_NAMESPACE}/test_depl1"), | ||
), | ||
op: add_operation(format_ptr!("/foo"), "bar".into()), | ||
}) | ||
.unwrap(); | ||
|
||
for event in annotated_trace.iter() { | ||
for obj in event.data.applied_objs.iter().chain(event.data.deleted_objs.iter()) { | ||
if obj.metadata.name == Some("test_depl1".into()) { | ||
assert_eq!(obj.data.get("foo").unwrap(), "bar"); | ||
} else { | ||
assert_none!(obj.data.get("foo")); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.