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