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

Function TestEnvFromConfig

cel/env_test.go:611–1099  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

609}
610
611func TestEnvFromConfig(t *testing.T) {
612 type exprCase struct {
613 name string
614 in any
615 expr string
616 iss error
617 out ref.Val
618 }
619 tests := []struct {
620 name string
621 beforeOpts []EnvOption
622 afterOpts []EnvOption
623 conf *env.Config
624 confHandlers []ConfigOptionFactory
625 exprs []exprCase
626 }{
627 {
628 name: "std env",
629 conf: env.NewConfig("std env"),
630 exprs: []exprCase{
631 {
632 name: "literal",
633 expr: "'hello world'",
634 out: types.String("hello world"),
635 },
636 {
637 name: "size",
638 expr: "'hello world'.size()",
639 out: types.Int(11),
640 },
641 },
642 },
643 {
644 name: "std env - imports",
645 beforeOpts: []EnvOption{Types(&proto3pb.TestAllTypes{})},
646 conf: env.NewConfig("std env - imports").
647 AddImports(env.NewImport("google.expr.proto3.test.TestAllTypes")),
648 exprs: []exprCase{
649 {
650 name: "literal",
651 expr: "TestAllTypes{single_int64: 15}.single_int64",
652 out: types.Int(15),
653 },
654 },
655 },
656 {
657 name: "std env - context proto",
658 beforeOpts: []EnvOption{Types(&proto3pb.TestAllTypes{})},
659 conf: env.NewConfig("std env - context proto").
660 SetContainer("google.expr.proto3.test").
661 SetContextVariable(env.NewContextVariable("google.expr.proto3.test.TestAllTypes")),
662 exprs: []exprCase{
663 {
664 name: "field select literal",
665 in: mustContextProto(t, &proto3pb.TestAllTypes{SingleInt64: 10}),
666 expr: "TestAllTypes{single_int64: single_int64}.single_int64",
667 out: types.Int(10),
668 },

Callers

nothing calls this directly

Calls 15

CELTypeProviderMethod · 0.95
CompileMethod · 0.95
ProgramMethod · 0.95
NewConfigFunction · 0.92
StringTypeAlias · 0.92
IntTypeAlias · 0.92
NewImportFunction · 0.92
NewContextVariableFunction · 0.92
NewFeatureFunction · 0.92
JSONFieldNamesFunction · 0.92
NewVariableFunction · 0.92
NewTypeDescFunction · 0.92

Tested by

no test coverage detected