(t *testing.T)
| 43 | } |
| 44 | |
| 45 | func TestLoadFile(t *testing.T) { |
| 46 | reg := NewRegistry() |
| 47 | fd := loadFile(t, reg, ` |
| 48 | name: 'example.proto' |
| 49 | package: 'example' |
| 50 | options < go_package: 'github.com/grpc-ecosystem/grpc-gateway/runtime/internal/example' > |
| 51 | message_type < |
| 52 | name: 'ExampleMessage' |
| 53 | field < |
| 54 | name: 'str' |
| 55 | label: LABEL_OPTIONAL |
| 56 | type: TYPE_STRING |
| 57 | number: 1 |
| 58 | > |
| 59 | > |
| 60 | `) |
| 61 | |
| 62 | file := reg.files["example.proto"] |
| 63 | if file == nil { |
| 64 | t.Errorf("reg.files[%q] = nil; want non-nil", "example.proto") |
| 65 | return |
| 66 | } |
| 67 | wantPkg := GoPackage{Path: "github.com/grpc-ecosystem/grpc-gateway/runtime/internal/example", Name: "example"} |
| 68 | if got, want := file.GoPkg, wantPkg; got != want { |
| 69 | t.Errorf("file.GoPkg = %#v; want %#v", got, want) |
| 70 | } |
| 71 | |
| 72 | msg, err := reg.LookupMsg("", ".example.ExampleMessage") |
| 73 | if err != nil { |
| 74 | t.Errorf("reg.LookupMsg(%q, %q)) failed with %v; want success", "", ".example.ExampleMessage", err) |
| 75 | return |
| 76 | } |
| 77 | if got, want := msg.DescriptorProto, fd.MessageType[0]; got != want { |
| 78 | t.Errorf("reg.lookupMsg(%q, %q).DescriptorProto = %#v; want %#v", "", ".example.ExampleMessage", got, want) |
| 79 | } |
| 80 | if got, want := msg.File, file; got != want { |
| 81 | t.Errorf("msg.File = %v; want %v", got, want) |
| 82 | } |
| 83 | if got := msg.Outers; got != nil { |
| 84 | t.Errorf("msg.Outers = %v; want %v", got, nil) |
| 85 | } |
| 86 | if got, want := len(msg.Fields), 1; got != want { |
| 87 | t.Errorf("len(msg.Fields) = %d; want %d", got, want) |
| 88 | } else if got, want := msg.Fields[0].FieldDescriptorProto, fd.MessageType[0].Field[0]; got != want { |
| 89 | t.Errorf("msg.Fields[0].FieldDescriptorProto = %v; want %v", got, want) |
| 90 | } else if got, want := msg.Fields[0].Message, msg; got != want { |
| 91 | t.Errorf("msg.Fields[0].Message = %v; want %v", got, want) |
| 92 | } |
| 93 | |
| 94 | if got, want := len(file.Messages), 1; got != want { |
| 95 | t.Errorf("file.Meeesages = %#v; want %#v", file.Messages, []*Message{msg}) |
| 96 | } |
| 97 | if got, want := file.Messages[0], msg; got != want { |
| 98 | t.Errorf("file.Meeesages[0] = %v; want %v", got, want) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | func TestLoadFileNestedPackage(t *testing.T) { |
nothing calls this directly
no test coverage detected