Skip to content

Commit

Permalink
Enable conformance tests for extensions (#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones committed Apr 22, 2024
1 parent 028e53c commit 057d4c8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ go_repository(
# CEL Spec deps
go_repository(
name = "com_google_cel_spec",
commit = "1bc3fb168317fa77d1227c52d0becbf2d358c023",
commit = "91f3cb1a7590f594a392b607ae9cab5e969b4cf3",
importpath = "github.com/google/cel-spec",
)

Expand Down
3 changes: 3 additions & 0 deletions conformance/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ ALL_TESTS = [
"@com_google_cel_spec//tests/simple:testdata/lists.textproto",
"@com_google_cel_spec//tests/simple:testdata/logic.textproto",
"@com_google_cel_spec//tests/simple:testdata/macros.textproto",
"@com_google_cel_spec//tests/simple:testdata/math_ext.textproto",
"@com_google_cel_spec//tests/simple:testdata/namespace.textproto",
"@com_google_cel_spec//tests/simple:testdata/optionals.textproto",
"@com_google_cel_spec//tests/simple:testdata/parse.textproto",
"@com_google_cel_spec//tests/simple:testdata/plumbing.textproto",
"@com_google_cel_spec//tests/simple:testdata/proto2.textproto",
"@com_google_cel_spec//tests/simple:testdata/proto3.textproto",
"@com_google_cel_spec//tests/simple:testdata/string.textproto",
"@com_google_cel_spec//tests/simple:testdata/string_ext.textproto",
"@com_google_cel_spec//tests/simple:testdata/timestamps.textproto",
"@com_google_cel_spec//tests/simple:testdata/unknowns.textproto",
"@com_google_cel_spec//tests/simple:testdata/wrappers.textproto",
Expand All @@ -37,6 +39,7 @@ sh_test(
# Failing conformance tests.
"--skip_test=fields/qualified_identifier_resolution/map_key_float,map_key_null,map_value_repeat_key",
"--skip_test=fields/qualified_identifier_resolution/map_value_repeat_key_heterogeneous",
"--skip_test=macros/map/map_extract_keys",
"--skip_test=timestamps/duration_converters/get_milliseconds",

# Future enhancments.
Expand Down
1 change: 1 addition & 0 deletions server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//cel:go_default_library",
"//common/types:go_default_library",
"//common/types/ref:go_default_library",
"//ext:go_default_library",
"@com_google_cel_spec//proto/test/v1/proto2:test_all_types_go_proto",
"@com_google_cel_spec//proto/test/v1/proto3:test_all_types_go_proto",
"@org_golang_google_genproto_googleapis_api//expr/conformance/v1alpha1:go_default_library",
Expand Down
17 changes: 15 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/google/cel-go/cel"
"github.com/google/cel-go/common/types"
"github.com/google/cel-go/common/types/ref"
"github.com/google/cel-go/ext"

test2pb "github.com/google/cel-spec/proto/test/v1/proto2/test_all_types"
test3pb "github.com/google/cel-spec/proto/test/v1/proto3/test_all_types"
Expand All @@ -41,7 +42,11 @@ func (s *ConformanceServer) Parse(ctx context.Context, in *confpb.ParseRequest)
return nil, invalidArgument("No source code.")
}
// NOTE: syntax_version isn't currently used
var parseOptions []cel.EnvOption
parseOptions := []cel.EnvOption{
ext.Math(),
ext.Protos(),
ext.Bindings(),
}
if in.DisableMacros {
parseOptions = append(parseOptions, cel.ClearMacros())
}
Expand All @@ -68,7 +73,12 @@ func (s *ConformanceServer) Check(ctx context.Context, in *confpb.CheckRequest)
return nil, invalidArgument("No source info.")
}
// Build the environment.
var checkOptions []cel.EnvOption = []cel.EnvOption{cel.StdLib()}
checkOptions := []cel.EnvOption{
cel.StdLib(),
ext.Strings(),
ext.Math(),
ext.Encoders(),
}
if in.NoStdEnv {
checkOptions = []cel.EnvOption{}
}
Expand Down Expand Up @@ -255,6 +265,9 @@ var evalEnv *cel.Env

func init() {
evalEnv, _ = cel.NewEnv(
ext.Strings(),
ext.Math(),
ext.Encoders(),
cel.Types(&test2pb.TestAllTypes{}, &test3pb.TestAllTypes{}),
cel.EagerlyValidateDeclarations(true),
cel.OptionalTypes())
Expand Down

0 comments on commit 057d4c8

Please sign in to comment.