(t *testing.T)
| 602 | } |
| 603 | |
| 604 | func TestDynamicProto(t *testing.T) { |
| 605 | b, err := os.ReadFile("testdata/team.fds") |
| 606 | if err != nil { |
| 607 | t.Fatalf("os.ReadFile() failed: %v", err) |
| 608 | } |
| 609 | var fds descpb.FileDescriptorSet |
| 610 | if err = proto.Unmarshal(b, &fds); err != nil { |
| 611 | t.Fatalf("proto.Unmarshal() failed: %v", err) |
| 612 | } |
| 613 | files := (&fds).GetFile() |
| 614 | fileCopy := make([]any, len(files)) |
| 615 | for i := 0; i < len(files); i++ { |
| 616 | fileCopy[i] = files[i] |
| 617 | } |
| 618 | pbFiles, err := protodesc.NewFiles(&fds) |
| 619 | if err != nil { |
| 620 | t.Fatalf("protodesc.NewFiles() failed: %v", err) |
| 621 | } |
| 622 | e := testEnv(t, |
| 623 | Container("cel"), |
| 624 | // The following is identical to registering the FileDescriptorSet; |
| 625 | // however, it tests a different code path which aggregates individual |
| 626 | // FileDescriptorProto values together. |
| 627 | TypeDescs(fileCopy...), |
| 628 | // Additionally, demonstrate that double registration of files doesn't |
| 629 | // cause any problems. |
| 630 | TypeDescs(pbFiles), |
| 631 | ) |
| 632 | src := `testdata.Team{name: 'X-Men', members: [ |
| 633 | testdata.Mutant{name: 'Jean Grey', level: 20}, |
| 634 | testdata.Mutant{name: 'Cyclops', level: 7}, |
| 635 | testdata.Mutant{name: 'Storm', level: 7}, |
| 636 | testdata.Mutant{name: 'Wolverine', level: 11} |
| 637 | ]}` |
| 638 | ast, iss := e.Compile(src) |
| 639 | if iss.Err() != nil { |
| 640 | t.Fatalf("env.Compile(%s) failed: %v", src, iss.Err()) |
| 641 | } |
| 642 | prg, err := e.Program(ast, EvalOptions(OptOptimize)) |
| 643 | if err != nil { |
| 644 | t.Fatalf("env.Program() failed: %v", err) |
| 645 | } |
| 646 | out, _, err := prg.Eval(NoVars()) |
| 647 | if err != nil { |
| 648 | t.Fatalf("program.Eval() failed: %v", err) |
| 649 | } |
| 650 | obj, ok := out.(traits.Indexer) |
| 651 | if !ok { |
| 652 | t.Fatalf("unable to convert output to object: %v", out) |
| 653 | } |
| 654 | if obj.Get(types.String("name")).Equal(types.String("X-Men")) == types.False { |
| 655 | t.Fatalf("got field 'name' %v, wanted X-Men", obj.Get(types.String("name"))) |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | func TestDynamicProtoFileDescriptors(t *testing.T) { |
| 660 | b, err := os.ReadFile("testdata/team.fds") |
nothing calls this directly
no test coverage detected