(t *testing.T)
| 337 | } |
| 338 | |
| 339 | func TestRego_MatchesParameters(t *testing.T) { |
| 340 | regoContent, err := os.ReadFile("testfiles/matches_parameters.rego") |
| 341 | require.NoError(t, err) |
| 342 | |
| 343 | r := NewEngine() |
| 344 | policy := &engine.Policy{ |
| 345 | Name: "matches-parameters-test", |
| 346 | Source: regoContent, |
| 347 | } |
| 348 | |
| 349 | t.Run("high expectation matches low severity", func(t *testing.T) { |
| 350 | matches, err := r.MatchesParameters(context.TODO(), policy, |
| 351 | map[string]string{"severity": "low"}, |
| 352 | map[string]string{"severity": "high"}) |
| 353 | require.NoError(t, err) |
| 354 | assert.True(t, matches) |
| 355 | }) |
| 356 | |
| 357 | t.Run("medium expectation does not match high severity", func(t *testing.T) { |
| 358 | matches, err := r.MatchesParameters(context.TODO(), policy, |
| 359 | map[string]string{"severity": "high"}, |
| 360 | map[string]string{"severity": "medium"}) |
| 361 | require.NoError(t, err) |
| 362 | assert.False(t, matches) |
| 363 | }) |
| 364 | |
| 365 | t.Run("critical severity matches critical expectation", func(t *testing.T) { |
| 366 | matches, err := r.MatchesParameters(context.TODO(), policy, |
| 367 | map[string]string{"severity": "critical"}, |
| 368 | map[string]string{"severity": "critical"}) |
| 369 | require.NoError(t, err) |
| 370 | assert.True(t, matches) |
| 371 | }) |
| 372 | |
| 373 | t.Run("unknown severity parameter", func(t *testing.T) { |
| 374 | matches, err := r.MatchesParameters(context.TODO(), policy, |
| 375 | map[string]string{"severity": "unknown"}, |
| 376 | map[string]string{"severity": "medium"}) |
| 377 | require.NoError(t, err) |
| 378 | assert.False(t, matches) |
| 379 | }) |
| 380 | |
| 381 | t.Run("empty parameters", func(t *testing.T) { |
| 382 | matches, err := r.MatchesParameters(context.TODO(), policy, |
| 383 | map[string]string{}, |
| 384 | map[string]string{}) |
| 385 | require.NoError(t, err) |
| 386 | assert.False(t, matches) |
| 387 | }) |
| 388 | } |
| 389 | |
| 390 | func TestRego_MatchesEvaluation(t *testing.T) { |
| 391 | regoContent, err := os.ReadFile("testfiles/matches_evaluation.rego") |
nothing calls this directly
no test coverage detected