@@ -27,6 +27,7 @@ pub struct ScanResult {
2727 policies : HashMap < String , Arc < Policy > > ,
2828 policy_bundles : HashMap < String , Arc < PolicyBundle > > ,
2929 accepted_risks : HashMap < String , Arc < AcceptedRisk > > ,
30+ global_evaluation : EvaluationResult ,
3031}
3132
3233impl ScanResult {
@@ -41,6 +42,7 @@ impl ScanResult {
4142 architecture : Architecture ,
4243 labels : HashMap < String , String > ,
4344 created_at : DateTime < Utc > ,
45+ global_evaluation : EvaluationResult ,
4446 ) -> Self {
4547 Self {
4648 scan_type,
@@ -60,6 +62,7 @@ impl ScanResult {
6062 policies : HashMap :: new ( ) ,
6163 policy_bundles : HashMap :: new ( ) ,
6264 accepted_risks : HashMap :: new ( ) ,
65+ global_evaluation,
6366 }
6467 }
6568
@@ -242,15 +245,7 @@ impl ScanResult {
242245 }
243246
244247 pub fn evaluation_result ( & self ) -> EvaluationResult {
245- if self
246- . policies ( )
247- . iter ( )
248- . all ( |p| p. evaluation_result ( ) . is_passed ( ) )
249- {
250- EvaluationResult :: Passed
251- } else {
252- EvaluationResult :: Failed
253- }
248+ self . global_evaluation
254249 }
255250}
256251
@@ -277,6 +272,7 @@ mod tests {
277272 Architecture :: Amd64 ,
278273 HashMap :: new ( ) ,
279274 Utc :: now ( ) ,
275+ EvaluationResult :: Failed ,
280276 )
281277 }
282278
@@ -505,7 +501,18 @@ mod tests {
505501
506502 #[ test]
507503 fn evaluation_result_passed ( ) {
508- let mut scan_result = create_scan_result ( ) ;
504+ let mut scan_result = ScanResult :: new (
505+ ScanType :: Docker ,
506+ "alpine:latest" . to_string ( ) ,
507+ "sha256:12345" . to_string ( ) ,
508+ Some ( "sha256:67890" . to_string ( ) ) ,
509+ OperatingSystem :: new ( Family :: Linux , "alpine:3.18" . to_string ( ) ) ,
510+ 123456 ,
511+ Architecture :: Amd64 ,
512+ HashMap :: new ( ) ,
513+ Utc :: now ( ) ,
514+ EvaluationResult :: Passed ,
515+ ) ;
509516 let now = Utc :: now ( ) ;
510517 let policy =
511518 scan_result. add_policy ( "policy-1" . to_string ( ) , "My Policy" . to_string ( ) , now, now) ;
@@ -758,7 +765,11 @@ mod tests {
758765
759766 assert_eq ! ( bundle. evaluation_result( ) , EvaluationResult :: Passed ) ;
760767 assert_eq ! ( policy. evaluation_result( ) , EvaluationResult :: Passed ) ;
761- assert_eq ! ( scan_result. evaluation_result( ) , EvaluationResult :: Passed ) ;
768+ assert_eq ! (
769+ scan_result. evaluation_result( ) ,
770+ EvaluationResult :: Failed ,
771+ "Global evaluation should remain Failed"
772+ ) ;
762773
763774 let failed_rule = bundle. add_rule (
764775 "rule-failed" . to_string ( ) ,
@@ -780,6 +791,10 @@ mod tests {
780791
781792 assert_eq ! ( bundle. evaluation_result( ) , EvaluationResult :: Failed ) ;
782793 assert_eq ! ( policy. evaluation_result( ) , EvaluationResult :: Failed ) ;
783- assert_eq ! ( scan_result. evaluation_result( ) , EvaluationResult :: Failed ) ;
794+ assert_eq ! (
795+ scan_result. evaluation_result( ) ,
796+ EvaluationResult :: Failed ,
797+ "Global evaluation should remain Failed"
798+ ) ;
784799 }
785800}
0 commit comments