@@ -500,33 +500,41 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test the compliance history API",
500
500
501
501
// Ensure the ConstraintTemplate has 1 event
502
502
g .Expect (policyToEventDetails ["complianceapitest" ]).To (HaveLen (1 ))
503
- g .Expect (policyToEventDetails ["complianceapitest" ][0 ]["compliance" ]).To (Equal ("Compliant" ))
504
- expectedMsg := "ConstraintTemplate complianceapitest was created successfully"
505
- g .Expect (policyToEventDetails ["complianceapitest" ][0 ]["message" ]).To (Equal (expectedMsg ))
503
+ msg := policyToEventDetails ["complianceapitest" ][0 ]["message" ]
504
+ g .Expect (policyToEventDetails ["complianceapitest" ][0 ]["compliance" ]).To (
505
+ Equal ("Compliant" ),
506
+ fmt .Sprintf ("The ConstraintTemplate was not compliant on cluster %s: %s" , cluster , msg ),
507
+ )
508
+ g .Expect (msg ).To (Equal ("ConstraintTemplate complianceapitest was created successfully" ))
506
509
507
510
// Ensure the constraint has 2 or more events. More than one template-error compliance event can
508
511
// be set based on race conditions.
509
512
lenOk := len (policyToEventDetails ["compliance-api" ]) >= 2
510
513
g .Expect (lenOk ).To (
511
514
BeTrue (),
512
515
fmt .Sprintf (
513
- "Expected the compliance-api policy to have 2 or more compliance events, got %d" ,
514
- len (policyToEventDetails ["compliance-api" ]),
516
+ "Expected the compliance-api policy to have 2 or more compliance events, got %d on cluster %s " ,
517
+ len (policyToEventDetails ["compliance-api" ]), cluster ,
515
518
),
516
519
)
517
520
// Sorted by timestamp in descending order
518
521
g .Expect (policyToEventDetails ["compliance-api" ][0 ]["compliance" ]).To (Equal ("NonCompliant" ))
519
- expectedMsg = "warn - All configmaps must have a 'my-gk-test' label (on ConfigMap " +
522
+ expectedMsg : = "warn - All configmaps must have a 'my-gk-test' label (on ConfigMap " +
520
523
"compliance-api-test/compliance-api-test)"
521
- g .Expect (policyToEventDetails ["compliance-api" ][0 ]["message" ]).To (Equal (expectedMsg ))
524
+ g .Expect (policyToEventDetails ["compliance-api" ][0 ]["message" ]).To (
525
+ Equal (expectedMsg ),
526
+ "The constraint compliance message didn't match on cluster " + cluster ,
527
+ )
522
528
523
529
// All other compliance events should be a template-error
524
530
for _ , eventDetails := range policyToEventDetails ["compliance-api" ][1 :] {
525
531
g .Expect (eventDetails ["compliance" ]).To (Equal ("NonCompliant" ))
526
532
expectedMsg = "template-error; Mapping not found, check if the required ConstraintTemplate has " +
527
533
"been deployed: the resource version was not found: constraints.gatekeeper.sh/v1beta1, " +
528
534
"Kind=ComplianceAPITest"
529
- g .Expect (eventDetails ["message" ]).To (Equal (expectedMsg ))
535
+ g .Expect (eventDetails ["message" ]).To (
536
+ Equal (expectedMsg ), "Unexpected constraint NonCompliant event on cluster " + cluster ,
537
+ )
530
538
}
531
539
}
532
540
// It can take a while for the Gatekeeper audit pod to produce audit results.
@@ -557,7 +565,10 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test the compliance history API",
557
565
g .Expect (events ).To (HaveLen (1 ), fmt .Sprintf ("expected cluster %s to have one compliant event" , cluster ))
558
566
559
567
eventDetails := events [0 ].(map [string ]interface {})["event" ].(map [string ]interface {})
560
- g .Expect (eventDetails ["compliance" ]).To (Equal ("Compliant" ))
568
+ g .Expect (eventDetails ["compliance" ]).To (
569
+ Equal ("Compliant" ),
570
+ fmt .Sprintf ("The constraint was not compliant on cluster %s: %s" , cluster , eventDetails ["message" ]),
571
+ )
561
572
g .Expect (eventDetails ["message" ]).To (Equal ("The constraint has no violations" ))
562
573
}
563
574
}, defaultTimeoutSeconds * 2 , 1 ).Should (Succeed ())
0 commit comments