MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestCompose_SourceInfo

Function TestCompose_SourceInfo

policy/composer_test.go:13–53  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestCompose_SourceInfo(t *testing.T) {
14 policyYAML := `name: test_policy
15rule:
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
55func TestCompose_Unnest(t *testing.T) {
56 policyYAML := `name: unnest

Callers

nothing calls this directly

Calls 12

ParseMethod · 0.95
ComposeMethod · 0.95
NewEnvFunction · 0.92
OptionalTypesFunction · 0.92
BindingsFunction · 0.92
StringSourceFunction · 0.85
CompileRuleFunction · 0.85
NewRuleComposerFunction · 0.85
verifySourceInfoTransferFunction · 0.85
ErrMethod · 0.80
NewParserFunction · 0.70
SourceInfoMethod · 0.45

Tested by

no test coverage detected