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

Function TestEnvFromConfig

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

Source from the content-addressed store, hash-verified

469}
470
471func TestEnvFromConfig(t *testing.T) {
472 type exprCase struct {
473 name string
474 in any
475 expr string
476 iss error
477 out ref.Val
478 }
479 tests := []struct {
480 name string
481 beforeOpts []EnvOption
482 afterOpts []EnvOption
483 conf *env.Config
484 confHandlers []ConfigOptionFactory
485 exprs []exprCase
486 }{
487 {
488 name: "std env",
489 conf: env.NewConfig("std env"),
490 exprs: []exprCase{
491 {
492 name: "literal",
493 expr: "'hello world'",
494 out: types.String("hello world"),
495 },
496 {
497 name: "size",
498 expr: "'hello world'.size()",
499 out: types.Int(11),
500 },
501 },
502 },
503 {
504 name: "std env - imports",
505 beforeOpts: []EnvOption{Types(&proto3pb.TestAllTypes{})},
506 conf: env.NewConfig("std env - imports").
507 AddImports(env.NewImport("google.expr.proto3.test.TestAllTypes")),
508 exprs: []exprCase{
509 {
510 name: "literal",
511 expr: "TestAllTypes{single_int64: 15}.single_int64",
512 out: types.Int(15),
513 },
514 },
515 },
516 {
517 name: "std env - context proto",
518 beforeOpts: []EnvOption{Types(&proto3pb.TestAllTypes{})},
519 conf: env.NewConfig("std env - context proto").
520 SetContainer("google.expr.proto3.test").
521 SetContextVariable(env.NewContextVariable("google.expr.proto3.test.TestAllTypes")),
522 exprs: []exprCase{
523 {
524 name: "field select literal",
525 in: mustContextProto(t, &proto3pb.TestAllTypes{SingleInt64: 10}),
526 expr: "TestAllTypes{single_int64: single_int64}.single_int64",
527 out: types.Int(10),
528 },

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