(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestProtoFiles(t *testing.T) { |
| 20 | cases := []struct { |
| 21 | Name string |
| 22 | DSL func() |
| 23 | }{ |
| 24 | {"protofiles-unary-rpcs", testdata.UnaryRPCsDSL}, |
| 25 | {"protofiles-unary-rpc-no-payload", testdata.UnaryRPCNoPayloadDSL}, |
| 26 | {"protofiles-unary-rpc-no-result", testdata.UnaryRPCNoResultDSL}, |
| 27 | {"protofiles-server-streaming-rpc", testdata.ServerStreamingRPCDSL}, |
| 28 | {"protofiles-client-streaming-rpc", testdata.ClientStreamingRPCDSL}, |
| 29 | {"protofiles-bidirectional-streaming-rpc", testdata.BidirectionalStreamingRPCDSL}, |
| 30 | {"protofiles-same-service-and-message-name", testdata.MessageWithServiceNameDSL}, |
| 31 | {"protofiles-method-with-reserved-proto-name", testdata.MethodWithReservedNameDSL}, |
| 32 | {"protofiles-multiple-methods-same-return-type", testdata.MultipleMethodsSameResultCollectionDSL}, |
| 33 | {"protofiles-method-with-acronym", testdata.MethodWithAcronymDSL}, |
| 34 | {"protofiles-custom-package-name", testdata.ServiceWithPackageDSL}, |
| 35 | {"protofiles-struct-meta-type", testdata.StructMetaTypeDSL}, |
| 36 | {"protofiles-default-fields", testdata.DefaultFieldsDSL}, |
| 37 | {"protofiles-custom-message-name", testdata.CustomMessageNameDSL}, |
| 38 | } |
| 39 | for _, c := range cases { |
| 40 | t.Run(c.Name, func(t *testing.T) { |
| 41 | root := RunGRPCDSL(t, c.DSL) |
| 42 | services := CreateGRPCServices(root) |
| 43 | fs := ProtoFiles("", services) |
| 44 | if len(fs) != 1 { |
| 45 | t.Fatalf("got %d files, expected one", len(fs)) |
| 46 | } |
| 47 | sections := fs[0].SectionTemplates |
| 48 | require.GreaterOrEqual(t, len(sections), 3) |
| 49 | code := sectionCode(t, sections[1:]...) |
| 50 | // testutil.AssertString handles line ending normalization internally |
| 51 | testutil.AssertString(t, "testdata/golden/proto_"+c.Name+".proto.golden", code) |
| 52 | fpath := codegen.CreateTempFile(t, code) |
| 53 | assert.NoError(t, protoc(defaultProtocCmd, fpath, nil), "error occurred when compiling proto file %q", fpath) |
| 54 | }) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestMessageDefSection(t *testing.T) { |
| 59 | cases := []struct { |
nothing calls this directly
no test coverage detected