MCPcopy Create free account
hub / github.com/goadesign/goa / TestProtoFiles

Function TestProtoFiles

grpc/codegen/proto_test.go:19–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func 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
58func TestMessageDefSection(t *testing.T) {
59 cases := []struct {

Callers

nothing calls this directly

Calls 8

AssertStringFunction · 0.92
CreateTempFileFunction · 0.92
RunGRPCDSLFunction · 0.85
CreateGRPCServicesFunction · 0.85
ProtoFilesFunction · 0.85
sectionCodeFunction · 0.85
protocFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected