TestStreamingErrorsWithValidation verifies that custom errors with validation rules are properly validated in streaming recv methods.
(t *testing.T)
| 83 | // TestStreamingErrorsWithValidation verifies that custom errors with |
| 84 | // validation rules are properly validated in streaming recv methods. |
| 85 | func TestStreamingErrorsWithValidation(t *testing.T) { |
| 86 | root := RunGRPCDSL(t, testdata.ServerStreamingWithCustomErrorsDSL) |
| 87 | services := CreateGRPCServices(root) |
| 88 | |
| 89 | // Verify the DSL has errors with validation |
| 90 | require.Len(t, root.Services, 1) |
| 91 | svc := root.Services[0] |
| 92 | require.Len(t, svc.Methods, 1) |
| 93 | method := svc.Methods[0] |
| 94 | require.Greater(t, len(method.Errors), 0, "method should have errors defined") |
| 95 | |
| 96 | // Generate client code |
| 97 | clientfs := ClientFiles("", services) |
| 98 | require.Greater(t, len(clientfs), 0) |
| 99 | |
| 100 | // Check recv implementations |
| 101 | recvSections := clientfs[0].Section("client-stream-recv") |
| 102 | var code strings.Builder |
| 103 | for _, section := range recvSections { |
| 104 | require.NoError(t, section.Write(&code)) |
| 105 | } |
| 106 | recvCode := code.String() |
| 107 | |
| 108 | // For errors with validation, verify validation is called |
| 109 | if strings.Contains(recvCode, "ValidateServerStreamCustomErrorError") { |
| 110 | assert.Contains(t, recvCode, "if err := ValidateServerStreamCustomErrorError(message); err != nil {", |
| 111 | "should validate custom error before returning") |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // TestStreamingErrorComparison compares error handling between unary and |
| 116 | // streaming methods to ensure consistency. |
nothing calls this directly
no test coverage detected