(t *testing.T)
| 224 | } |
| 225 | |
| 226 | func TestComparisonWarnRule(t *testing.T) { |
| 227 | policyContent := `package main |
| 228 | |
| 229 | import rego.v1 |
| 230 | |
| 231 | # METADATA |
| 232 | # title: Always warn |
| 233 | # custom: |
| 234 | # short_name: always_warn |
| 235 | warn contains result if { |
| 236 | result := { |
| 237 | "code": "main.always_warn", |
| 238 | "msg": "This is a warning", |
| 239 | } |
| 240 | } |
| 241 | ` |
| 242 | pair := setupEvaluatorPair(t, policyContent, ecc.Source{}) |
| 243 | ctx := context.Background() |
| 244 | inputPath := writeInput(t, map[string]any{"test": "value"}) |
| 245 | |
| 246 | target := EvaluationTarget{Inputs: []string{inputPath}, Target: "image:latest"} |
| 247 | |
| 248 | cr, err := pair.conftest.Evaluate(ctx, target) |
| 249 | require.NoError(t, err) |
| 250 | or, err := pair.opa.Evaluate(ctx, target) |
| 251 | require.NoError(t, err) |
| 252 | |
| 253 | assertSameOutcomes(t, "always-warn", cr, or) |
| 254 | assert.Contains(t, summarizeOutcomes(cr).warningCodes, "main.always_warn") |
| 255 | } |
| 256 | |
| 257 | func TestComparisonMixedDenyAndWarn(t *testing.T) { |
| 258 | policyContent := `package main |
nothing calls this directly
no test coverage detected