| 229 | } |
| 230 | |
| 231 | func 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 | |
| 271 | func TestHTTPAuthorizationMapping(t *testing.T) { |
| 272 | cases := []struct { |