(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestClient(t *testing.T) { |
| 17 | cases := []struct { |
| 18 | Name string |
| 19 | DSL func() |
| 20 | Code string |
| 21 | }{ |
| 22 | {"client-single", testdata.SingleEndpointDSL, testdata.SingleMethodClient}, |
| 23 | {"client-use", testdata.UseEndpointDSL, testdata.UseMethodClient}, |
| 24 | {"client-multiple", testdata.MultipleEndpointsDSL, testdata.MultipleMethodsClient}, |
| 25 | {"client-no-payload", testdata.NoPayloadEndpointDSL, testdata.NoPayloadMethodsClient}, |
| 26 | {"client-with-result", testdata.WithResultEndpointDSL, testdata.WithResultMethodClient}, |
| 27 | {"client-streaming-result", testdata.StreamingResultMethodDSL, testdata.StreamingResultMethodClient}, |
| 28 | {"client-mixed-results", testdata.MixedResultsEndpointDSL, testdata.MixedResultsMethodClient}, |
| 29 | {"client-streaming-result-no-payload", testdata.StreamingResultNoPayloadMethodDSL, testdata.StreamingResultNoPayloadMethodClient}, |
| 30 | {"client-streaming-payload", testdata.StreamingPayloadMethodDSL, testdata.StreamingPayloadMethodClient}, |
| 31 | {"client-streaming-payload-no-payload", testdata.StreamingPayloadNoPayloadMethodDSL, testdata.StreamingPayloadNoPayloadMethodClient}, |
| 32 | {"client-streaming-payload-no-result", testdata.StreamingPayloadNoResultMethodDSL, testdata.StreamingPayloadNoResultMethodClient}, |
| 33 | {"client-bidirectional-streaming", testdata.BidirectionalStreamingMethodDSL, testdata.BidirectionalStreamingMethodClient}, |
| 34 | {"client-bidirectional-streaming-no-payload", testdata.BidirectionalStreamingNoPayloadMethodDSL, testdata.BidirectionalStreamingNoPayloadMethodClient}, |
| 35 | {"client-interceptor", testdata.EndpointWithClientInterceptorDSL, testdata.InterceptorClient}, |
| 36 | {"client-interceptor-no-method", testdata.NoMethodClientInterceptorDSL, testdata.NoMethodInterceptorClient}, |
| 37 | } |
| 38 | for _, c := range cases { |
| 39 | t.Run(c.Name, func(t *testing.T) { |
| 40 | root := codegen.RunDSL(t, c.DSL) |
| 41 | services := NewServicesData(root) |
| 42 | require.Len(t, root.Services, 1) |
| 43 | fs := ClientFile("test/gen", root.Services[0], services) |
| 44 | require.NotNil(t, fs) |
| 45 | buf := new(bytes.Buffer) |
| 46 | for _, s := range fs.SectionTemplates[1:] { |
| 47 | require.NoError(t, s.Write(buf)) |
| 48 | } |
| 49 | bs, err := format.Source(buf.Bytes()) |
| 50 | require.NoError(t, err, buf.String()) |
| 51 | code := strings.ReplaceAll(string(bs), "\r\n", "\n") |
| 52 | assert.Equal(t, c.Code, code) |
| 53 | }) |
| 54 | } |
| 55 | } |
nothing calls this directly
no test coverage detected