-
-
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: show validation results in xray
- Loading branch information
Showing
19 changed files
with
325 additions
and
161 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 |
---|---|---|
@@ -1,43 +1,72 @@ | ||
mod status_field_populated_test; | ||
mod validation_store_test; | ||
|
||
use std::collections::BTreeMap; | ||
|
||
use rstest::*; | ||
use sk_core::k8s::testutils::test_deployment; | ||
use sk_store::TraceEvent; | ||
|
||
use super::annotated_trace::AnnotatedTraceEvent; | ||
use super::validator::{ | ||
Diagnostic, | ||
Validator, | ||
ValidatorCode, | ||
ValidatorType, | ||
}; | ||
use super::*; | ||
|
||
const TEST_VALIDATOR_CODE: ValidatorCode = ValidatorCode(ValidatorType::Error, 9999); | ||
|
||
#[fixture] | ||
pub fn annotated_trace() -> AnnotatedTrace { | ||
AnnotatedTrace::new_with_events(vec![ | ||
AnnotatedTraceEvent { | ||
data: TraceEvent { ts: 0, ..Default::default() }, | ||
..Default::default() | ||
}, | ||
AnnotatedTraceEvent { | ||
data: TraceEvent { | ||
ts: 1, | ||
applied_objs: vec![test_deployment("test_depl1")], | ||
deleted_objs: vec![], | ||
}, | ||
..Default::default() | ||
}, | ||
AnnotatedTraceEvent { | ||
data: TraceEvent { | ||
ts: 2, | ||
applied_objs: vec![test_deployment("test_depl1"), test_deployment("test_depl2")], | ||
deleted_objs: vec![], | ||
}, | ||
..Default::default() | ||
}, | ||
AnnotatedTraceEvent { | ||
data: TraceEvent { | ||
ts: 3, | ||
applied_objs: vec![], | ||
deleted_objs: vec![test_deployment("test_depl1")], | ||
}, | ||
..Default::default() | ||
}, | ||
AnnotatedTraceEvent::new(TraceEvent { ts: 0, ..Default::default() }), | ||
AnnotatedTraceEvent::new(TraceEvent { | ||
ts: 1, | ||
applied_objs: vec![test_deployment("test_depl1")], | ||
deleted_objs: vec![], | ||
}), | ||
AnnotatedTraceEvent::new(TraceEvent { | ||
ts: 2, | ||
applied_objs: vec![test_deployment("test_depl1"), test_deployment("test_depl2")], | ||
deleted_objs: vec![], | ||
}), | ||
AnnotatedTraceEvent::new(TraceEvent { | ||
ts: 3, | ||
applied_objs: vec![], | ||
deleted_objs: vec![test_deployment("test_depl1")], | ||
}), | ||
]) | ||
} | ||
|
||
struct TestDiagnostic {} | ||
|
||
impl Diagnostic for TestDiagnostic { | ||
fn check_next_event(&mut self, evt: &mut AnnotatedTraceEvent) -> Vec<usize> { | ||
if evt.data.applied_objs.len() > 1 { | ||
vec![1] | ||
} else { | ||
vec![] | ||
} | ||
} | ||
|
||
fn reset(&mut self) {} | ||
} | ||
|
||
#[fixture] | ||
fn test_validator() -> Validator { | ||
Validator { | ||
type_: ValidatorType::Warning, | ||
name: "test_validator", | ||
help: "HELP ME, I'M STUCK IN THE BORROW CHECKER", | ||
diagnostic: Box::new(TestDiagnostic {}), | ||
} | ||
} | ||
|
||
#[fixture] | ||
pub fn test_validation_store(test_validator: Validator) -> ValidationStore { | ||
let mut test_store = ValidationStore { validators: BTreeMap::new() }; | ||
test_store.register_with_code(TEST_VALIDATOR_CODE, test_validator); | ||
test_store | ||
} |
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 |
---|---|---|
@@ -1,53 +1,20 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use assertables::*; | ||
|
||
use super::validator::{ | ||
Diagnostic, | ||
Validator, | ||
ValidatorType, | ||
}; | ||
use super::*; | ||
|
||
struct TestDiagnostic {} | ||
|
||
impl Diagnostic for TestDiagnostic { | ||
fn check_next_event(&mut self, evt: &mut AnnotatedTraceEvent) -> Vec<usize> { | ||
if evt.data.applied_objs.len() > 1 { | ||
vec![1] | ||
} else { | ||
vec![] | ||
} | ||
} | ||
|
||
fn reset(&mut self) {} | ||
} | ||
|
||
#[fixture] | ||
fn validator() -> Validator { | ||
Validator { | ||
type_: ValidatorType::Warning, | ||
name: "test_validator", | ||
help: "HELP ME, I'M STUCK IN THE BORROW CHECKER", | ||
diagnostic: Box::new(TestDiagnostic {}), | ||
} | ||
} | ||
|
||
#[rstest] | ||
fn test_validate_trace(validator: Validator, mut annotated_trace: AnnotatedTrace) { | ||
let code = "W9999"; | ||
let mut test_store = ValidationStore { validators: BTreeMap::new() }; | ||
test_store.register_with_code(code.into(), validator); | ||
|
||
test_store.validate_trace(&mut annotated_trace); | ||
fn test_validate_trace(mut test_validation_store: ValidationStore, mut annotated_trace: AnnotatedTrace) { | ||
test_validation_store.validate_trace(&mut annotated_trace); | ||
|
||
for evt in annotated_trace.iter() { | ||
if evt.data.applied_objs.len() > 1 { | ||
assert_eq!(evt.annotations, vec![(1, code.into())]); | ||
assert_eq!(evt.annotations[1], vec![TEST_VALIDATOR_CODE]); | ||
} else { | ||
assert_is_empty!(evt.annotations); | ||
for annotation in &evt.annotations { | ||
assert_is_empty!(annotation); | ||
} | ||
} | ||
} | ||
|
||
assert_eq!(annotated_trace.summary_for(code).unwrap(), 1); | ||
assert_eq!(annotated_trace.summary_for(&TEST_VALIDATOR_CODE).unwrap(), 1); | ||
} |
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
Oops, something went wrong.