Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a30d67d
Add k8s custom policy tag handler for test
aakash070 Feb 4, 2025
77aab71
added copyright and removed redundant attribute from go_library target
aakash070 Feb 5, 2025
9e155af
refactor code to extract common methods
aakash070 Mar 10, 2025
73bba9e
reverted redundant code
aakash070 Mar 11, 2025
7afe78c
added compiler tool
aakash070 Mar 12, 2025
d261979
replaced textproto file with an in memory pb object
aakash070 Mar 21, 2025
6cb138d
reverted update to root go.mod
aakash070 Mar 25, 2025
5cab162
added cel.dev/expr/conformance to vendor
aakash070 Mar 25, 2025
907b6c3
add vendor to tools
aakash070 Mar 25, 2025
09f6866
deleted tools/vendor
aakash070 Mar 25, 2025
bf7624c
Add test runner library
aakash070 Apr 2, 2025
afdf755
created test runner option for test suite parser
aakash070 Apr 2, 2025
e6028d1
update test suite structure
aakash070 Apr 4, 2025
98be9bd
fix test suite path used to set up test suite parser
aakash070 Apr 4, 2025
dcfc1a0
updated cel.dev/expr version in WORKSPACE
aakash070 Apr 7, 2025
a8a77f5
updated go registered toolchain version in WORKSPACE
aakash070 Apr 7, 2025
3c58df5
updated checksum for cel.dev/expr in WORKSPACE
aakash070 Apr 7, 2025
b867b8a
update cel.dev/expr release version to resolve failing tests
aakash070 Apr 7, 2025
9b8248c
fix vendor verification error
aakash070 Apr 7, 2025
bf96c47
resolved pr comments on YAML test suite and test runner
aakash070 Apr 8, 2025
449ba4f
update test runner to accept any type options instead of TestRunnerOp…
aakash070 Apr 8, 2025
b8c7496
replaced functional test suite parsers with an interface
aakash070 Apr 9, 2025
f942827
update test suite schema in policy testdata files
aakash070 Apr 10, 2025
61399be
added sync once as a compiler object level variable
aakash070 Apr 10, 2025
2dad2f3
fix test failure
aakash070 Apr 10, 2025
c101087
added test for test runner for standard policy
aakash070 Apr 10, 2025
156addf
added tests for custom policy parser via flags
aakash070 Apr 11, 2025
f2022c3
moved test for custom policy from compiler test to test runner test
aakash070 Apr 14, 2025
59cf7ee
changed argument type for Test Suite Parser methods to string
aakash070 Apr 14, 2025
70d7f5f
added tests for raw CEL expression and CEL expression file
aakash070 Apr 14, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
created test runner option for test suite parser
  • Loading branch information
aakash070 committed Apr 15, 2025
commit afdf755cbf79e051bfcba9fc2cc66e6ea64f6588
38 changes: 21 additions & 17 deletions tools/celtest/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ type TestSuiteParserTextproto func(*testing.T, any) (*conformancepb.TestSuite, e
// The object can be serialized in a YAML file or derived programamtically.
type TestSuiteParserYAML func(*testing.T, any) (*test.Suite, error)

// TriggerTestsFromCompiler triggers tests for a CEL checked expression with the provided
// set of options. The options can be used to:
// 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
func TriggerTestsFromCompiler(t *testing.T, opts ...any) {
opts = append([]any{TestRunnerOption(testSuiteParser)}, opts...)
func TriggerTests(t *testing.T, opts ...any) {
opts = append([]any{TestSuiteParser(testSuitePath)}, opts...)
tr, err := NewTestRunner(opts...)
if err != nil {
t.Fatalf("error creating test runner: %v", err)
Expand All @@ -123,21 +123,25 @@ func TriggerTestsFromCompiler(t *testing.T, opts ...any) {
}
}

func testSuiteParser(tr *TestRunner) (*TestRunner, error) {
if testSuitePath == "" {
// TestSuiteParser provides a TestRunnerOption that sets the test suite file path and the test
// suite parser based on the file format: YAML or Textproto.
func TestSuiteParser(path string) TestRunnerOption {
return func(tr *TestRunner) (*TestRunner, error) {
if testSuitePath == "" {
return tr, nil
}
tr.TestSuiteFilePath = testSuitePath
testSuiteFormat := compiler.InferFileFormat(testSuitePath)
switch testSuiteFormat {
case compiler.TextProto:
tr.TestSuiteParserTextproto = DefaultTestSuiteParserTextproto
case compiler.TextYAML:
tr.TestSuiteParserYAML = DefaultTestSuiteParserYAML
default:
return nil, fmt.Errorf("unsupported test suite file format: %v", testSuiteFormat)
}
return tr, nil
}
tr.TestSuiteFilePath = testSuitePath
testSuiteFormat := compiler.InferFileFormat(testSuitePath)
switch testSuiteFormat {
case compiler.TextProto:
tr.TestSuiteParserTextproto = DefaultTestSuiteParserTextproto
case compiler.TextYAML:
tr.TestSuiteParserYAML = DefaultTestSuiteParserYAML
default:
return nil, fmt.Errorf("unsupported test suite file format: %v", testSuiteFormat)
}
return tr, nil
}

// TestRunner provides a structure to hold the different components required to execute tests for
Expand Down