Programs creates a list of CEL programs from the input expressions configured in the test runner using the provided program options.
(t *testing.T, opts ...cel.ProgramOption)
| 572 | // Programs creates a list of CEL programs from the input expressions configured in the test runner |
| 573 | // using the provided program options. |
| 574 | func (tr *TestRunner) Programs(t *testing.T, opts ...cel.ProgramOption) ([]Program, error) { |
| 575 | t.Helper() |
| 576 | if tr.Compiler == nil { |
| 577 | return nil, fmt.Errorf("compiler is not set") |
| 578 | } |
| 579 | e, err := tr.CreateEnv() |
| 580 | if err != nil { |
| 581 | return nil, err |
| 582 | } |
| 583 | programs := make([]Program, 0, len(tr.Expressions)) |
| 584 | for _, expr := range tr.Expressions { |
| 585 | ast, policyMetadata, err := expr.CreateAST(tr.Compiler) |
| 586 | if err != nil { |
| 587 | if strings.Contains(err.Error(), "invalid file extension") || |
| 588 | strings.Contains(err.Error(), "invalid raw expression") { |
| 589 | continue |
| 590 | } |
| 591 | return nil, err |
| 592 | } |
| 593 | if enableDebug { |
| 594 | t.Logf("Loaded AST:\n%s", DebugAST(ast)) |
| 595 | } |
| 596 | prg, err := e.Program(ast, opts...) |
| 597 | if err != nil { |
| 598 | return nil, err |
| 599 | } |
| 600 | programs = append(programs, Program{ |
| 601 | Program: prg, |
| 602 | PolicyMetadata: policyMetadata, |
| 603 | Ast: ast, |
| 604 | }) |
| 605 | } |
| 606 | return programs, nil |
| 607 | } |
| 608 | |
| 609 | // Tests creates a list of tests from the test suite file and test suite parser configured in the |
| 610 | // test runner. |