TriggerTests triggers tests for a CEL policy, expression or checked expression with the provided set of options. The options can be used to: - configure the Compiler used for parsing and compiling the expression - configure the Test Runner used for parsing and executing the tests
(t *testing.T, testRunnerOpts ...TestRunnerOption)
| 139 | // - configure the Compiler used for parsing and compiling the expression |
| 140 | // - configure the Test Runner used for parsing and executing the tests |
| 141 | func TriggerTests(t *testing.T, testRunnerOpts ...TestRunnerOption) { |
| 142 | tr, err := NewTestRunner(testRunnerOpts...) |
| 143 | if err != nil { |
| 144 | t.Fatalf("error creating test runner: %v", err) |
| 145 | } |
| 146 | programs, err := tr.Programs(t, tr.testProgramOptions...) |
| 147 | if err != nil { |
| 148 | t.Fatalf("error creating programs: %v", err) |
| 149 | } |
| 150 | if len(programs) == 0 { |
| 151 | t.Fatalf("no programs created for the provided expressions") |
| 152 | } |
| 153 | tests, err := tr.Tests(t) |
| 154 | if err != nil { |
| 155 | t.Fatalf("error creating tests: %v", err) |
| 156 | } |
| 157 | if len(tests) == 0 { |
| 158 | t.Fatalf("no tests found") |
| 159 | } |
| 160 | for _, test := range tests { |
| 161 | t.Run(test.name, func(t *testing.T) { |
| 162 | err := tr.ExecuteTest(t, programs, test) |
| 163 | if err != nil { |
| 164 | t.Fatalf("error executing test: %v", err) |
| 165 | } |
| 166 | }) |
| 167 | } |
| 168 | if tr.EnableCoverage { |
| 169 | reportCoverage(t, programs) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // TestRunnerOptionsFromFlags returns a TestRunnerOption which configures the following attributes |
| 174 | // of the test runner using the parsed flags and the optionally provided test runner and test compiler options: |