diff --git a/codelab/src/test/codelab/testrunner/BUILD.bazel b/codelab/src/test/codelab/testrunner/BUILD.bazel new file mode 100644 index 000000000..0a89b7d76 --- /dev/null +++ b/codelab/src/test/codelab/testrunner/BUILD.bazel @@ -0,0 +1,199 @@ +load("@rules_java//java:java_library.bzl", "java_library") +load("//third_party/cel/expr:cel_test.bzl", "cel_test", "make_test_targets", "test_runtime") + +package( + default_applicable_licenses = ["//:license"], + default_testonly = 1, +) + +java_library( + name = "basic_user_test", + srcs = ["BasicUserTest.java"], + deps = [ + "//bundle:cel", + "//runtime:function_binding", + "//testing/testrunner:cel_test_context", + "//testing/testrunner:cel_user_test_template", + "@maven//:junit_junit", + ], +) + +java_library( + name = "error_output_user_test", + srcs = ["ErrorOutputUserTest.java"], + deps = [ + "//testing/testrunner:cel_test_context", + "//testing/testrunner:cel_user_test_template", + "@maven//:junit_junit", + ], +) + +java_library( + name = "context_proto_user_test", + srcs = ["ContextProtoUserTest.java"], + deps = [ + "//bundle:cel", + "//checker:proto_type_mask", + "//testing/testrunner:cel_test_context", + "//testing/testrunner:cel_user_test_template", + "@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto", + "@maven//:junit_junit", + ], +) + +java_library( + name = "late_function_binding_user_test", + srcs = ["LateFunctionBindingUserTest.java"], + deps = [ + "//bundle:cel", + "//runtime", + "//runtime:function_binding", + "//testing/testrunner:cel_test_context", + "//testing/testrunner:cel_user_test_template", + "@maven//:junit_junit", + ], +) + +java_library( + name = "custom_variable_binding_user_test", + srcs = ["CustomVariableBindingUserTest.java"], + deps = [ + "//bundle:cel", + "//runtime:function_binding", + "//testing/testrunner:cel_test_context", + "//testing/testrunner:cel_user_test_template", + "@maven//:com_google_guava_guava", + "@maven//:junit_junit", + ], +) + +java_library( + name = "custom_test_suite", + srcs = ["CustomTestSuite.java"], + deps = [ + "//testing/testrunner:annotations", + "//testing/testrunner:cel_test_suite", + "@maven//:com_google_guava_guava", + ], +) + +cel_test( + name = "example_0_test", + cel_expr = "basictest/expression.cel", + config = "basictest/config.yaml", + filegroup = "//codelab:testrunner_codelab_resources", # Users can use exports_files with appropriate visibility in which case filegroup is not required. + test_data_path = "//codelab/src/test/codelab/testrunner/resources", + test_suite = "basictest/testsuite.yaml", + test_targets = [make_test_targets( + runtime = test_runtime.JAVA, + test_srcs = [":basic_user_test"], + )], +) + +cel_test( + name = "example_0_test_with_raw_expression", + cel_expr = "foo(a) || bar(a) == true", + config = "basictest/config.yaml", + filegroup = "//codelab:testrunner_codelab_resources", + is_raw_expr = True, + test_data_path = "//codelab/src/test/codelab/testrunner/resources", + test_suite = "basictest/testsuite.yaml", + test_targets = [make_test_targets( + runtime = test_runtime.JAVA, + test_srcs = [":basic_user_test"], + )], +) + +cel_test( + name = "example_0_test_with_policy", + cel_expr = "basictest/policy.yaml", + config = "basictest/config.yaml", + filegroup = "//codelab:testrunner_codelab_resources", + test_data_path = "//codelab/src/test/codelab/testrunner/resources", + test_suite = "basictest/testsuite.yaml", + test_targets = [make_test_targets( + runtime = test_runtime.JAVA, + test_srcs = [":basic_user_test"], + )], +) + +cel_test( + name = "example_1_test", + cel_expr = "foo(a) || bar(a) == true", + config = "basictest/config.yaml", + filegroup = "//codelab:testrunner_codelab_resources", + is_raw_expr = True, + test_data_path = "//codelab/src/test/codelab/testrunner/resources", + test_suite = "unknownoutputtest/testsuite.yaml", + test_targets = [make_test_targets( + runtime = test_runtime.JAVA, + test_srcs = [":basic_user_test"], + )], +) + +cel_test( + name = "example_2_test", + cel_expr = "basictest/policy.yaml", + config = "basictest/config.yaml", + filegroup = "//codelab:testrunner_codelab_resources", + test_data_path = "//codelab/src/test/codelab/testrunner/resources", + test_suite = "erroroutputtest/testsuite.yaml", + test_targets = [make_test_targets( + runtime = test_runtime.JAVA, + test_srcs = [":error_output_user_test"], + )], +) + +cel_test( + name = "example_4_test", + cel_expr = "basictest/expression.cel", + config = "basictest/config.yaml", + filegroup = "//codelab:testrunner_codelab_resources", + test_data_path = "//codelab/src/test/codelab/testrunner/resources", + test_targets = [make_test_targets( + runtime = test_runtime.JAVA, + test_srcs = [":basic_user_test"], + deps = [":custom_test_suite"], + )], +) + +cel_test( + name = "example_5_test", + cel_expr = "foo(a) || bar(a) == true", + config = "basictest/config.yaml", + filegroup = "//codelab:testrunner_codelab_resources", + is_raw_expr = True, + test_data_path = "//codelab/src/test/codelab/testrunner/resources", + test_suite = "customvariablebindingtest/testsuite.yaml", + test_targets = [make_test_targets( + runtime = test_runtime.JAVA, + test_srcs = [":custom_variable_binding_user_test"], + )], +) + +cel_test( + name = "example_6_test", + cel_expr = "contextprototest/policy.yaml", + config = "contextprototest/config.yaml", + filegroup = "//codelab:testrunner_codelab_resources", + test_data_path = "//codelab/src/test/codelab/testrunner/resources", + test_suite = "contextprototest/testsuite.yaml", + test_targets = [make_test_targets( + runtime = test_runtime.JAVA, + test_srcs = [":context_proto_user_test"], + )], +) + +cel_test( + name = "example_7_test", + cel_expr = "foo(a) || bar(a) == true", + config = "basictest/config.yaml", + filegroup = "//codelab:testrunner_codelab_resources", + is_raw_expr = True, + test_data_path = "//codelab/src/test/codelab/testrunner/resources", + test_suite = "basictest/testsuite.yaml", + test_targets = [make_test_targets( + runtime = test_runtime.JAVA, + test_srcs = [":late_function_binding_user_test"], + )], +) diff --git a/codelab/src/test/codelab/testrunner/BasicUserTest.java b/codelab/src/test/codelab/testrunner/BasicUserTest.java new file mode 100644 index 000000000..367fc54e6 --- /dev/null +++ b/codelab/src/test/codelab/testrunner/BasicUserTest.java @@ -0,0 +1,42 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package codelab.testrunner; + +import dev.cel.bundle.CelFactory; +import dev.cel.runtime.CelFunctionBinding; +import dev.cel.testing.testrunner.CelTestContext; +import dev.cel.testing.testrunner.CelUserTestTemplate; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** A sample basic user test class demonstrating a basic user journey. */ +@RunWith(Parameterized.class) +public class BasicUserTest extends CelUserTestTemplate { + + public BasicUserTest() { + super( + CelTestContext.newBuilder() + .setCel( + CelFactory.standardCelBuilder() + .addFunctionBindings( + CelFunctionBinding.from( + "foo_id", String.class, (String a) -> a.equals("foo"))) + .addFunctionBindings( + CelFunctionBinding.from( + "bar_id", String.class, (String a) -> a.equals("bar"))) + .build()) + .build()); + } +} diff --git a/codelab/src/test/codelab/testrunner/ContextProtoUserTest.java b/codelab/src/test/codelab/testrunner/ContextProtoUserTest.java new file mode 100644 index 000000000..45527ebad --- /dev/null +++ b/codelab/src/test/codelab/testrunner/ContextProtoUserTest.java @@ -0,0 +1,44 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package codelab.testrunner; + +import dev.cel.bundle.CelFactory; +import dev.cel.checker.ProtoTypeMask; +import dev.cel.expr.conformance.proto3.TestAllTypes; +import dev.cel.testing.testrunner.CelTestContext; +import dev.cel.testing.testrunner.CelUserTestTemplate; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + * This test demonstrates the use case where the fields of a proto are used as variables in the CEL + * expression i.e. context_expr. + */ +@RunWith(Parameterized.class) +public class ContextProtoUserTest extends CelUserTestTemplate { + + public ContextProtoUserTest() { + super( + CelTestContext.newBuilder() + .setCel( + CelFactory.standardCelBuilder() + .addFileTypes(TestAllTypes.getDescriptor().getFile()) + .addProtoTypeMasks( + ProtoTypeMask.ofAllFields(TestAllTypes.getDescriptor().getFullName()) + .withFieldsAsVariableDeclarations()) + .build()) + .build()); + } +} diff --git a/codelab/src/test/codelab/testrunner/CustomTestSuite.java b/codelab/src/test/codelab/testrunner/CustomTestSuite.java new file mode 100644 index 000000000..84745af3a --- /dev/null +++ b/codelab/src/test/codelab/testrunner/CustomTestSuite.java @@ -0,0 +1,62 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package codelab.testrunner; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import dev.cel.testing.testrunner.Annotations.TestSuiteSupplier; +import dev.cel.testing.testrunner.CelTestSuite; +import dev.cel.testing.testrunner.CelTestSuite.CelTestSection.CelTestCase.Input.Binding; + +public final class CustomTestSuite { + + @TestSuiteSupplier + public CelTestSuite getCelTestSuite() { + return CelTestSuite.newBuilder() + .setDescription("Basic Tests") + .setName("basic_tests") + .setSections( + ImmutableSet.of( + CelTestSuite.CelTestSection.newBuilder() + .setName("basic_test_sections") + .setDescription("Basic Tests Sections") + .setTests( + ImmutableSet.of( + CelTestSuite.CelTestSection.CelTestCase.newBuilder() + .setName("true_by_default") + .setDescription( + "Test that the default value of a function is true.") + .setInput( + CelTestSuite.CelTestSection.CelTestCase.Input.ofBindings( + ImmutableMap.of("a", Binding.ofValue("foo")))) + .setOutput( + CelTestSuite.CelTestSection.CelTestCase.Output.ofResultValue( + true)) + .build(), + CelTestSuite.CelTestSection.CelTestCase.newBuilder() + .setName("false_by_default") + .setDescription( + "Test that the default value of a function is false.") + .setInput( + CelTestSuite.CelTestSection.CelTestCase.Input.ofBindings( + ImmutableMap.of("a", Binding.ofValue("baz")))) + .setOutput( + CelTestSuite.CelTestSection.CelTestCase.Output.ofResultValue( + false)) + .build())) + .build())) + .build(); + } +} diff --git a/codelab/src/test/codelab/testrunner/CustomVariableBindingUserTest.java b/codelab/src/test/codelab/testrunner/CustomVariableBindingUserTest.java new file mode 100644 index 000000000..3a05b8bed --- /dev/null +++ b/codelab/src/test/codelab/testrunner/CustomVariableBindingUserTest.java @@ -0,0 +1,47 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package codelab.testrunner; + +import com.google.common.collect.ImmutableMap; +import dev.cel.bundle.CelFactory; +import dev.cel.runtime.CelFunctionBinding; +import dev.cel.testing.testrunner.CelTestContext; +import dev.cel.testing.testrunner.CelUserTestTemplate; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + * A sample user test class demonstrating custom variable binding in which we don't provide the + * input values from testsuite rather programmatically via {@link CelTestContext}. + */ +@RunWith(Parameterized.class) +public class CustomVariableBindingUserTest extends CelUserTestTemplate { + + public CustomVariableBindingUserTest() { + super( + CelTestContext.newBuilder() + .setCel( + CelFactory.standardCelBuilder() + .addFunctionBindings( + CelFunctionBinding.from( + "foo_id", String.class, (String a) -> a.equals("foo"))) + .addFunctionBindings( + CelFunctionBinding.from( + "bar_id", String.class, (String a) -> a.equals("bar"))) + .build()) + .setVariableBindings(ImmutableMap.of("a", "foo")) + .build()); + } +} diff --git a/codelab/src/test/codelab/testrunner/ErrorOutputUserTest.java b/codelab/src/test/codelab/testrunner/ErrorOutputUserTest.java new file mode 100644 index 000000000..3f4de1e45 --- /dev/null +++ b/codelab/src/test/codelab/testrunner/ErrorOutputUserTest.java @@ -0,0 +1,32 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package codelab.testrunner; + +import dev.cel.testing.testrunner.CelTestContext; +import dev.cel.testing.testrunner.CelUserTestTemplate; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** + * A sample user test class demonstrating error output assertion. Here we don't bind the function + * implementations which should result in error. + */ +@RunWith(Parameterized.class) +public class ErrorOutputUserTest extends CelUserTestTemplate { + + public ErrorOutputUserTest() { + super(CelTestContext.newBuilder().build()); + } +} diff --git a/codelab/src/test/codelab/testrunner/LateFunctionBindingUserTest.java b/codelab/src/test/codelab/testrunner/LateFunctionBindingUserTest.java new file mode 100644 index 000000000..a2b44f147 --- /dev/null +++ b/codelab/src/test/codelab/testrunner/LateFunctionBindingUserTest.java @@ -0,0 +1,39 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package codelab.testrunner; + +import dev.cel.bundle.CelFactory; +import dev.cel.runtime.CelFunctionBinding; +import dev.cel.runtime.CelLateFunctionBindings; +import dev.cel.testing.testrunner.CelTestContext; +import dev.cel.testing.testrunner.CelUserTestTemplate; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +/** A sample user test class demonstrating late function binding. */ +@RunWith(Parameterized.class) +public class LateFunctionBindingUserTest extends CelUserTestTemplate { + + public LateFunctionBindingUserTest() { + super( + CelTestContext.newBuilder() + .setCel(CelFactory.standardCelBuilder().build()) + .setCelLateFunctionBindings( + CelLateFunctionBindings.from( + CelFunctionBinding.from("bar_id", String.class, (String a) -> a.equals("bar")), + CelFunctionBinding.from("foo_id", String.class, (String a) -> a.equals("foo")))) + .build()); + } +} diff --git a/codelab/src/test/codelab/testrunner/resources/BUILD.bazel b/codelab/src/test/codelab/testrunner/resources/BUILD.bazel new file mode 100644 index 000000000..84518ac95 --- /dev/null +++ b/codelab/src/test/codelab/testrunner/resources/BUILD.bazel @@ -0,0 +1,21 @@ +package( + default_applicable_licenses = [ + "//:license", + ], + default_testonly = True, + default_visibility = [ + "//codelab:__pkg__", + ], +) + +filegroup( + name = "testrunner_codelab_data_files", + srcs = glob([ + "**/*.yaml", + "**/*.textproto", + "**/*.cel", + "**/*.celpolicy", + ]), + tags = [ + ], +) diff --git a/codelab/src/test/codelab/testrunner/resources/basictest/config.yaml b/codelab/src/test/codelab/testrunner/resources/basictest/config.yaml new file mode 100644 index 000000000..423db293b --- /dev/null +++ b/codelab/src/test/codelab/testrunner/resources/basictest/config.yaml @@ -0,0 +1,34 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: "late_function_binding" +functions: + - name: "foo" + overloads: + - id: 'foo_id' + args: + - type_name: 'string' + return: + type_name: 'bool' + - name: "bar" + overloads: + - id: 'bar_id' + args: + - type_name: 'string' + return: + type_name: 'bool' +variables: + - name: "a" + type: + type_name: 'string' \ No newline at end of file diff --git a/codelab/src/test/codelab/testrunner/resources/basictest/expression.cel b/codelab/src/test/codelab/testrunner/resources/basictest/expression.cel new file mode 100644 index 000000000..fa212241f --- /dev/null +++ b/codelab/src/test/codelab/testrunner/resources/basictest/expression.cel @@ -0,0 +1 @@ +foo(a) || bar(a) == true \ No newline at end of file diff --git a/codelab/src/test/codelab/testrunner/resources/basictest/policy.yaml b/codelab/src/test/codelab/testrunner/resources/basictest/policy.yaml new file mode 100644 index 000000000..e980fcdcf --- /dev/null +++ b/codelab/src/test/codelab/testrunner/resources/basictest/policy.yaml @@ -0,0 +1,20 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: "basic_test" +rule: + match: + - condition: foo(a) || bar(a) + output: "true" + - output: "false" diff --git a/codelab/src/test/codelab/testrunner/resources/basictest/testsuite.yaml b/codelab/src/test/codelab/testrunner/resources/basictest/testsuite.yaml new file mode 100644 index 000000000..e3f726675 --- /dev/null +++ b/codelab/src/test/codelab/testrunner/resources/basictest/testsuite.yaml @@ -0,0 +1,34 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: "basic_tests" +description: "Basic Tests" +sections: + - name: "basic_test_sections" + description: "Basic Tests Sections" + tests: + - name: "true_by_default" + description: "Test that the default value of a function is true." + input: + a: + expr: "'foo'" + output: + value: true + - name: "false_by_default" + description: "Test that the default value of a function is false." + input: + a: + value: "baz" + output: + value: false \ No newline at end of file diff --git a/codelab/src/test/codelab/testrunner/resources/contextprototest/config.yaml b/codelab/src/test/codelab/testrunner/resources/contextprototest/config.yaml new file mode 100644 index 000000000..2ca7fac42 --- /dev/null +++ b/codelab/src/test/codelab/testrunner/resources/contextprototest/config.yaml @@ -0,0 +1,19 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: "context_pb" +container: "cel.expr.conformance.proto3" +extensions: + - name: "strings" + version: "latest" \ No newline at end of file diff --git a/codelab/src/test/codelab/testrunner/resources/contextprototest/policy.yaml b/codelab/src/test/codelab/testrunner/resources/contextprototest/policy.yaml new file mode 100644 index 000000000..8111bb76c --- /dev/null +++ b/codelab/src/test/codelab/testrunner/resources/contextprototest/policy.yaml @@ -0,0 +1,25 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: "context_pb" +rule: + match: + - condition: > + single_int32 > TestAllTypes{single_int64: 10}.single_int64 + output: | + ["invalid spec, got single_int32=" , single_int32 , ", wanted <= 10"].join() + - condition: > + standalone_enum == TestAllTypes.NestedEnum.BAR + output: | + "invalid spec, no nested enums may refer to BAR" \ No newline at end of file diff --git a/codelab/src/test/codelab/testrunner/resources/contextprototest/testsuite.yaml b/codelab/src/test/codelab/testrunner/resources/contextprototest/testsuite.yaml new file mode 100644 index 000000000..d37e2bee3 --- /dev/null +++ b/codelab/src/test/codelab/testrunner/resources/contextprototest/testsuite.yaml @@ -0,0 +1,35 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: "context_pb_cel_tests" +description: "Protobuf input tests" +sections: + - name: "valid" + description: "Valid context_expr" + tests: + - name: "good spec" + description: "good spec" + context_expr: + "TestAllTypes{single_int32: 10}" + output: + expr: "optional.none()" + - name: "invalid" + description: "Invalid context_expr" + tests: + - name: "bad spec" + description: "bad spec" + context_expr: + "TestAllTypes{single_int32: 11}" + output: + value: "invalid spec, got single_int32=11, wanted <= 10" \ No newline at end of file diff --git a/codelab/src/test/codelab/testrunner/resources/customvariablebindingtest/testsuite.yaml b/codelab/src/test/codelab/testrunner/resources/customvariablebindingtest/testsuite.yaml new file mode 100644 index 000000000..64ce3057d --- /dev/null +++ b/codelab/src/test/codelab/testrunner/resources/customvariablebindingtest/testsuite.yaml @@ -0,0 +1,24 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: "basic_tests" +description: "Basic Tests" +sections: + - name: "basic_test_sections" + description: "Basic Tests Sections" + tests: + - name: "true_by_default" + description: "Test that the default value of a function is true." + output: + value: true \ No newline at end of file diff --git a/codelab/src/test/codelab/testrunner/resources/erroroutputtest/testsuite.yaml b/codelab/src/test/codelab/testrunner/resources/erroroutputtest/testsuite.yaml new file mode 100644 index 000000000..4773cdfaa --- /dev/null +++ b/codelab/src/test/codelab/testrunner/resources/erroroutputtest/testsuite.yaml @@ -0,0 +1,28 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: "error_output_tests" +description: "Error Output Tests" +sections: + - name: "error_output_test_sections" + description: "Error Output Tests Sections" + tests: + - name: "true_by_default" + description: "Test that the default value of a function is true." + input: + a: + expr: "'foo'" + output: + error_set: + - "evaluation error: No matching overload for function 'foo'. Overload candidates: foo_id" \ No newline at end of file diff --git a/codelab/src/test/codelab/testrunner/resources/unknownoutputtest/testsuite.yaml b/codelab/src/test/codelab/testrunner/resources/unknownoutputtest/testsuite.yaml new file mode 100644 index 000000000..197d790db --- /dev/null +++ b/codelab/src/test/codelab/testrunner/resources/unknownoutputtest/testsuite.yaml @@ -0,0 +1,33 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: "unknown_output_tests" +description: "Unknown Output Tests" +sections: + - name: "unknown_output_test_sections" + description: "Unknown Output Tests Sections" + tests: + - name: "Unknown Output" + description: "Tests that the output is unknown due to input binding missing." + output: + unknown: + - 2 + - 5 + - name: "false_by_default" + description: "Test that the default value of a function is false." + input: + a: + value: "baz" + output: + value: false \ No newline at end of file