TestStreamingWithErrors tests that streaming endpoints properly handle custom errors defined in the service DSL.
(t *testing.T)
| 13 | // TestStreamingWithErrors tests that streaming endpoints properly handle |
| 14 | // custom errors defined in the service DSL. |
| 15 | func TestStreamingWithErrors(t *testing.T) { |
| 16 | cases := []struct { |
| 17 | name string |
| 18 | dsl func() |
| 19 | testFunc func(t *testing.T, code string) |
| 20 | }{ |
| 21 | { |
| 22 | name: "server streaming with custom errors", |
| 23 | dsl: testdata.ServerStreamingWithCustomErrorsDSL, |
| 24 | testFunc: func(t *testing.T, code string) { |
| 25 | // Verify error decoding is present |
| 26 | assert.Contains(t, code, "goagrpc.DecodeError(err)", |
| 27 | "should decode errors from stream") |
| 28 | |
| 29 | // Verify custom error types are handled |
| 30 | assert.Contains(t, code, "case *streaming_error_servicepb.ServerStreamCustomErrorError:", |
| 31 | "should handle custom error type") |
| 32 | assert.Contains(t, code, "case *streaming_error_servicepb.ServerStreamValidationErrorError:", |
| 33 | "should handle validation error type") |
| 34 | |
| 35 | // Verify generic errors are handled |
| 36 | assert.Contains(t, code, "case *goapb.ErrorResponse:", |
| 37 | "should handle generic goa errors") |
| 38 | |
| 39 | // Verify proper error construction |
| 40 | assert.Contains(t, code, "NewServerStreamCustomErrorError(message", |
| 41 | "should construct custom error") |
| 42 | assert.Contains(t, code, "NewServerStreamValidationErrorError(message", |
| 43 | "should construct validation error") |
| 44 | }, |
| 45 | }, |
| 46 | { |
| 47 | name: "bidirectional streaming with errors", |
| 48 | dsl: testdata.BidirectionalStreamingRPCWithErrorsDSL, |
| 49 | testFunc: func(t *testing.T, code string) { |
| 50 | // Bidirectional streaming with simple errors should still decode |
| 51 | assert.Contains(t, code, "goagrpc.DecodeError(err)", |
| 52 | "should decode errors from bidirectional stream") |
| 53 | assert.Contains(t, code, "case *goapb.ErrorResponse:", |
| 54 | "should handle generic errors in bidirectional streaming") |
| 55 | }, |
| 56 | }, |
| 57 | } |
| 58 | |
| 59 | for _, c := range cases { |
| 60 | t.Run(c.name, func(t *testing.T) { |
| 61 | root := RunGRPCDSL(t, c.dsl) |
| 62 | services := CreateGRPCServices(root) |
| 63 | clientfs := ClientFiles("", services) |
| 64 | require.Greater(t, len(clientfs), 0) |
| 65 | |
| 66 | // Get recv method implementations |
| 67 | recvSections := clientfs[0].Section("client-stream-recv") |
| 68 | require.Greater(t, len(recvSections), 0) |
| 69 | |
| 70 | // Build complete recv method code |
| 71 | var codeBuilder strings.Builder |
| 72 | for _, section := range recvSections { |
nothing calls this directly
no test coverage detected