|
47 | 47 | sampleGCPolicyInput string |
48 | 48 | //go:embed samples/clamav-task.json |
49 | 49 | sampleClamAVTask string |
| 50 | + //go:embed samples/trusted-task.json |
| 51 | + sampleTrustedTask string |
| 52 | + //go:embed samples/untrusted-task.json |
| 53 | + sampleUntrustedTask string |
| 54 | + //go:embed samples/untrusted-task-despite-valid-oci-ref-tag.json |
| 55 | + sampleUntrustedTaskDespiteValidOciRefTag string |
50 | 56 | ) |
51 | 57 |
|
52 | 58 | type testStateKey struct{} |
@@ -105,6 +111,12 @@ func writeSampleGCPolicyInput(ctx context.Context, sampleName string) (context.C |
105 | 111 | content = sampleGCPolicyInput |
106 | 112 | case "clamav-task": |
107 | 113 | content = sampleClamAVTask |
| 114 | + case "trusted-task": |
| 115 | + content = sampleTrustedTask |
| 116 | + case "untrusted-task": |
| 117 | + content = sampleUntrustedTask |
| 118 | + case "untrusted-task-despite-valid-oci-ref-tag": |
| 119 | + content = sampleUntrustedTaskDespiteValidOciRefTag |
108 | 120 | default: |
109 | 121 | return ctx, fmt.Errorf("%q is not a known sample name", sampleName) |
110 | 122 | } |
@@ -191,6 +203,24 @@ func thereShouldBeNoViolationsInTheResult(ctx context.Context) error { |
191 | 203 | return nil |
192 | 204 | } |
193 | 205 |
|
| 206 | +func thereShouldBeViolationsInTheResult(ctx context.Context) error { |
| 207 | + ts, err := getTestState(ctx) |
| 208 | + if err != nil { |
| 209 | + return fmt.Errorf("reading test state: %w", err) |
| 210 | + } |
| 211 | + |
| 212 | + violationCount := 0 |
| 213 | + for _, filepath := range ts.report.FilePaths { |
| 214 | + violationCount += len(filepath.Violations) |
| 215 | + } |
| 216 | + |
| 217 | + if violationCount == 0 { |
| 218 | + return errors.New("expected violations, but got none") |
| 219 | + } |
| 220 | + |
| 221 | + return nil |
| 222 | +} |
| 223 | + |
194 | 224 | func thereShouldBeNoWarningsInTheResult(ctx context.Context) error { |
195 | 225 | ts, err := getTestState(ctx) |
196 | 226 | if err != nil { |
@@ -350,6 +380,7 @@ func InitializeScenario(sc *godog.ScenarioContext) { |
350 | 380 | sc.Step(`^a policy config:$`, writePolicyConfig) |
351 | 381 | sc.Step(`^input is validated$`, validateInputWithPolicyConfig) |
352 | 382 | sc.Step(`^there should be no violations in the result$`, thereShouldBeNoViolationsInTheResult) |
| 383 | + sc.Step(`^there should be violations in the result$`, thereShouldBeViolationsInTheResult) |
353 | 384 | sc.Step(`^there should be no warnings in the result$`, thereShouldBeNoWarningsInTheResult) |
354 | 385 | sc.Step(`^there should be no violations with "([^"]*)" collection in the result$`, thereShouldBeNoViolationsWithCollectionInTheResult) |
355 | 386 | sc.Step(`^there should be no violations with "([^"]*)" package in the result$`, thereShouldBeNoViolationsWithPackageInTheResult) |
|
0 commit comments