(t *testing.T)
| 469 | } |
| 470 | |
| 471 | func 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 | }, |
nothing calls this directly
no test coverage detected