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

Function TriggerTests

tools/celtest/test_runner.go:141–171  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

139// - configure the Compiler used for parsing and compiling the expression
140// - configure the Test Runner used for parsing and executing the tests
141func 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:

Callers 5

TestK8sCELFunction · 0.92
TestCELFunction · 0.92
TestTriggerTestsFunction · 0.85

Calls 5

ProgramsMethod · 0.95
TestsMethod · 0.95
ExecuteTestMethod · 0.95
NewTestRunnerFunction · 0.85
reportCoverageFunction · 0.85

Tested by 5

TestK8sCELFunction · 0.74
TestCELFunction · 0.74
TestTriggerTestsFunction · 0.68