(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestCompose_SourceInfo(t *testing.T) { |
| 14 | policyYAML := `name: test_policy |
| 15 | rule: |
| 16 | match: |
| 17 | - condition: "2 == 1" |
| 18 | output: "'hi'" |
| 19 | - output: "'hello' + ' world'" |
| 20 | ` |
| 21 | src := StringSource(policyYAML, "test_policy.yaml") |
| 22 | parser, err := NewParser() |
| 23 | if err != nil { |
| 24 | t.Fatalf("NewParser() failed: %v", err) |
| 25 | } |
| 26 | policy, iss := parser.Parse(src) |
| 27 | if iss.Err() != nil { |
| 28 | t.Fatalf("parser.Parse() failed: %v", iss.Err()) |
| 29 | } |
| 30 | |
| 31 | env, err := cel.NewEnv(cel.OptionalTypes(), ext.Bindings()) |
| 32 | if err != nil { |
| 33 | t.Fatalf("cel.NewEnv() failed: %v", err) |
| 34 | } |
| 35 | compiledRule, iss := CompileRule(env, policy) |
| 36 | if iss.Err() != nil { |
| 37 | t.Fatalf("CompileRule() failed: %v", iss.Err()) |
| 38 | } |
| 39 | composer, err := NewRuleComposer(env) |
| 40 | if err != nil { |
| 41 | t.Fatalf("NewRuleComposer() failed: %v", err) |
| 42 | } |
| 43 | compAST, iss := composer.Compose(compiledRule) |
| 44 | if iss.Err() != nil { |
| 45 | t.Fatalf("composer.Compose() failed: %v", iss.Err()) |
| 46 | } |
| 47 | |
| 48 | si := compAST.SourceInfo() |
| 49 | if si.Location != "test_policy.yaml" { |
| 50 | t.Errorf("SourceInfo.Location got %q, wanted test_policy.yaml", si.Location) |
| 51 | } |
| 52 | verifySourceInfoTransfer(t, compiledRule, compAST) |
| 53 | } |
| 54 | |
| 55 | func TestCompose_Unnest(t *testing.T) { |
| 56 | policyYAML := `name: unnest |
nothing calls this directly
no test coverage detected