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

Function TestStreamingErrorComparison

grpc/codegen/streaming_errors_test.go:117–191  ·  view source on GitHub ↗

TestStreamingErrorComparison compares error handling between unary and streaming methods to ensure consistency.

(t *testing.T)

Source from the content-addressed store, hash-verified

115// TestStreamingErrorComparison compares error handling between unary and
116// streaming methods to ensure consistency.
117func TestStreamingErrorComparison(t *testing.T) {
118 // DSL with both unary and streaming methods with errors
119 dsl := func() {
120 var CustomError = Type("CustomError", func() {
121 ErrorName("name", String, "error name")
122 Attribute("message", String, "error message")
123 Required("name", "message")
124 })
125
126 Service("MixedService", func() {
127 // Unary method with custom error
128 Method("UnaryMethod", func() {
129 Payload(String)
130 Result(String)
131 Error("custom_error", CustomError)
132 GRPC(func() {
133 Response("custom_error", CodeInvalidArgument)
134 })
135 })
136
137 // Streaming method with same error
138 Method("StreamingMethod", func() {
139 Payload(String)
140 StreamingResult(String)
141 Error("custom_error", CustomError)
142 GRPC(func() {
143 Response("custom_error", CodeInvalidArgument)
144 })
145 })
146 })
147 }
148
149 root := RunGRPCDSL(t, dsl)
150 services := CreateGRPCServices(root)
151 clientfs := ClientFiles("", services)
152 require.Greater(t, len(clientfs), 0, "should have client files")
153
154 // Find unary and streaming code in different sections
155 var unaryCode, streamCode string
156
157 // For unary, look in client-endpoint-init
158 if sections := clientfs[0].Section("client-endpoint-init"); len(sections) > 0 {
159 var code strings.Builder
160 for _, section := range sections {
161 require.NoError(t, section.Write(&code))
162 }
163 unaryCode = code.String()
164 }
165
166 // For streaming, look in client-stream-recv
167 if sections := clientfs[0].Section("client-stream-recv"); len(sections) > 0 {
168 var code strings.Builder
169 for _, section := range sections {
170 require.NoError(t, section.Write(&code))
171 }
172 streamCode = code.String()
173 }
174

Callers

nothing calls this directly

Calls 15

ErrorNameFunction · 0.85
AttributeFunction · 0.85
RequiredFunction · 0.85
MethodFunction · 0.85
PayloadFunction · 0.85
ResultFunction · 0.85
GRPCFunction · 0.85
StreamingResultFunction · 0.85
RunGRPCDSLFunction · 0.85
CreateGRPCServicesFunction · 0.85
SectionMethod · 0.80
ClientFilesFunction · 0.70

Tested by

no test coverage detected