(t *testing.T)
| 706 | } |
| 707 | |
| 708 | func TestDynamicProto(t *testing.T) { |
| 709 | b, err := os.ReadFile("testdata/team.fds") |
| 710 | if err != nil { |
| 711 | t.Fatalf("os.ReadFile() failed: %v", err) |
| 712 | } |
| 713 | var fds descpb.FileDescriptorSet |
| 714 | if err = proto.Unmarshal(b, &fds); err != nil { |
| 715 | t.Fatalf("proto.Unmarshal() failed: %v", err) |
| 716 | } |
| 717 | files := (&fds).GetFile() |
| 718 | fileCopy := make([]any, len(files)) |
| 719 | for i := 0; i < len(files); i++ { |
| 720 | fileCopy[i] = files[i] |
| 721 | } |
| 722 | pbFiles, err := protodesc.NewFiles(&fds) |
| 723 | if err != nil { |
| 724 | t.Fatalf("protodesc.NewFiles() failed: %v", err) |
| 725 | } |
| 726 | e := testEnv(t, |
| 727 | Container("cel"), |
| 728 | // The following is identical to registering the FileDescriptorSet; |
| 729 | // however, it tests a different code path which aggregates individual |
| 730 | // FileDescriptorProto values together. |
| 731 | TypeDescs(fileCopy...), |
| 732 | // Additionally, demonstrate that double registration of files doesn't |
| 733 | // cause any problems. |
| 734 | TypeDescs(pbFiles), |
| 735 | ) |
| 736 | src := `testdata.Team{name: 'X-Men', members: [ |
| 737 | testdata.Mutant{name: 'Jean Grey', level: 20}, |
| 738 | testdata.Mutant{name: 'Cyclops', level: 7}, |
| 739 | testdata.Mutant{name: 'Storm', level: 7}, |
| 740 | testdata.Mutant{name: 'Wolverine', level: 11} |
| 741 | ]}` |
| 742 | ast, iss := e.Compile(src) |
| 743 | if iss.Err() != nil { |
| 744 | t.Fatalf("env.Compile(%s) failed: %v", src, iss.Err()) |
| 745 | } |
| 746 | prg, err := e.Program(ast, EvalOptions(OptOptimize)) |
| 747 | if err != nil { |
| 748 | t.Fatalf("env.Program() failed: %v", err) |
| 749 | } |
| 750 | out, _, err := prg.Eval(NoVars()) |
| 751 | if err != nil { |
| 752 | t.Fatalf("program.Eval() failed: %v", err) |
| 753 | } |
| 754 | obj, ok := out.(traits.Indexer) |
| 755 | if !ok { |
| 756 | t.Fatalf("unable to convert output to object: %v", out) |
| 757 | } |
| 758 | if obj.Get(types.String("name")).Equal(types.String("X-Men")) == types.False { |
| 759 | t.Fatalf("got field 'name' %v, wanted X-Men", obj.Get(types.String("name"))) |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | func TestDynamicProtoFileDescriptors(t *testing.T) { |
| 764 | b, err := os.ReadFile("testdata/team.fds") |
nothing calls this directly
no test coverage detected