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

Function TestHTTPEndpointFinalization

expr/http_endpoint_test.go:231–269  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

229}
230
231func TestHTTPEndpointFinalization(t *testing.T) {
232 cases := map[string]struct {
233 DSL func()
234 ExpectedBody expr.DataType
235 }{
236 "body-as-extend-type": {
237 DSL: testdata.FinalizeEndpointBodyAsExtendedTypeDSL,
238 ExpectedBody: testdata.FinalizeEndpointBodyAsExtendedType,
239 },
240 "body-as-prop-with-extend-type": {
241 DSL: testdata.FinalizeEndpointBodyAsPropWithExtendedTypeDSL,
242 ExpectedBody: testdata.FinalizeEndpointBodyAsPropWithExtendedType,
243 },
244 }
245 for name, tc := range cases {
246 t.Run(name, func(t *testing.T) {
247 root := expr.RunDSL(t, tc.DSL)
248 e := root.API.HTTP.Services[0].HTTPEndpoints[0]
249
250 if tc.ExpectedBody != nil {
251 if e.Body == nil {
252 t.Errorf("got endpoint without body, expected endpoint with body")
253 return
254 }
255 bodyObj := *expr.AsObject(e.Body.Type)
256 expectedBodyObj := *expr.AsObject(tc.ExpectedBody)
257 if len(bodyObj) != len(expectedBodyObj) {
258 t.Errorf("got %d, expected %d attribute(s) in endpoint body", len(bodyObj), len(expectedBodyObj))
259 } else {
260 for i := range expectedBodyObj {
261 if bodyObj[i].Name != expectedBodyObj[i].Name {
262 t.Errorf("got %q, expected %q attribute in endpoint body", bodyObj[i].Name, expectedBodyObj[i].Name)
263 }
264 }
265 }
266 }
267 })
268 }
269}
270
271func TestHTTPAuthorizationMapping(t *testing.T) {
272 cases := []struct {

Callers

nothing calls this directly

Calls 3

RunDSLFunction · 0.92
AsObjectFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected