(t testing.TB, policyYAML, filename string, composerOpts ...ComposerOption)
| 285 | } |
| 286 | |
| 287 | func parseAndComposeRule(t testing.TB, policyYAML, filename string, composerOpts ...ComposerOption) (*cel.Env, *CompiledRule, *cel.Ast) { |
| 288 | t.Helper() |
| 289 | src := StringSource(policyYAML, filename) |
| 290 | parser, err := NewParser() |
| 291 | if err != nil { |
| 292 | t.Fatalf("NewParser() failed: %v", err) |
| 293 | } |
| 294 | policy, iss := parser.Parse(src) |
| 295 | if iss.Err() != nil { |
| 296 | t.Fatalf("parser.Parse() failed: %v", iss.Err()) |
| 297 | } |
| 298 | env, err := cel.NewEnv(cel.OptionalTypes(), ext.Bindings()) |
| 299 | if err != nil { |
| 300 | t.Fatalf("cel.NewEnv() failed: %v", err) |
| 301 | } |
| 302 | compiledRule, iss := CompileRule(env, policy) |
| 303 | if iss.Err() != nil { |
| 304 | t.Fatalf("CompileRule() failed: %v", iss.Err()) |
| 305 | } |
| 306 | composer, err := NewRuleComposer(env, composerOpts...) |
| 307 | if err != nil { |
| 308 | t.Fatalf("NewRuleComposer() failed: %v", err) |
| 309 | } |
| 310 | compAST, iss := composer.Compose(compiledRule) |
| 311 | if iss.Err() != nil { |
| 312 | t.Fatalf("composer.Compose() failed: %v", iss.Err()) |
| 313 | } |
| 314 | return env, compiledRule, compAST |
| 315 | } |
no test coverage detected