| 15 | ) |
| 16 | |
| 17 | func TestService(t *testing.T) { |
| 18 | cases := []struct { |
| 19 | Name string |
| 20 | DSL func() |
| 21 | }{ |
| 22 | {"service-name-with-spaces", testdata.NamesWithSpacesDSL}, |
| 23 | {"service-single", testdata.SingleMethodDSL}, |
| 24 | {"service-multiple", testdata.MultipleMethodsDSL}, |
| 25 | {"service-union", testdata.UnionMethodDSL}, |
| 26 | {"service-multi-union", testdata.MultiUnionMethodDSL}, |
| 27 | {"service-union-alias-cross-pkg", testdata.UnionWithAliasCrossPkgDSL}, |
| 28 | {"service-no-payload-no-result", testdata.EmptyMethodDSL}, |
| 29 | {"service-payload-no-result", testdata.EmptyResultMethodDSL}, |
| 30 | {"service-no-payload-result", testdata.EmptyPayloadMethodDSL}, |
| 31 | {"service-payload-result-with-default", testdata.WithDefaultDSL}, |
| 32 | {"service-result-with-multiple-views", testdata.MultipleMethodsResultMultipleViewsDSL}, |
| 33 | {"service-result-with-explicit-and-default-views", testdata.WithExplicitAndDefaultViewsDSL}, |
| 34 | {"service-result-collection-multiple-views", testdata.ResultCollectionMultipleViewsMethodDSL}, |
| 35 | {"service-result-with-other-result", testdata.ResultWithOtherResultMethodDSL}, |
| 36 | {"service-result-with-result-collection", testdata.ResultWithResultCollectionMethodDSL}, |
| 37 | {"service-result-with-dashed-mime-type", testdata.ResultWithDashedMimeTypeMethodDSL}, |
| 38 | {"service-result-with-one-of-type", testdata.ResultWithOneOfTypeMethodDSL}, |
| 39 | {"service-result-with-inline-validation", testdata.ResultWithInlineValidationDSL}, |
| 40 | {"service-service-level-error", testdata.ServiceErrorDSL}, |
| 41 | {"service-custom-errors", testdata.CustomErrorsDSL}, |
| 42 | {"service-custom-errors-custom-field", testdata.CustomErrorsCustomFieldDSL}, |
| 43 | {"service-force-generate-type", testdata.ForceGenerateTypeDSL}, |
| 44 | {"service-force-generate-type-explicit", testdata.ForceGenerateTypeExplicitDSL}, |
| 45 | {"service-streaming-result", testdata.StreamingResultMethodDSL}, |
| 46 | {"service-mixed-results", testdata.MixedResultsEndpointDSL}, |
| 47 | {"service-streaming-result-with-views", testdata.StreamingResultWithViewsMethodDSL}, |
| 48 | {"service-streaming-result-with-explicit-view", testdata.StreamingResultWithExplicitViewMethodDSL}, |
| 49 | {"service-streaming-result-no-payload", testdata.StreamingResultNoPayloadMethodDSL}, |
| 50 | {"service-streaming-payload", testdata.StreamingPayloadMethodDSL}, |
| 51 | {"service-streaming-payload-no-payload", testdata.StreamingPayloadNoPayloadMethodDSL}, |
| 52 | {"service-streaming-payload-no-result", testdata.StreamingPayloadNoResultMethodDSL}, |
| 53 | {"service-streaming-payload-result-with-views", testdata.StreamingPayloadResultWithViewsMethodDSL}, |
| 54 | {"service-streaming-payload-result-with-explicit-view", testdata.StreamingPayloadResultWithExplicitViewMethodDSL}, |
| 55 | {"service-bidirectional-streaming", testdata.BidirectionalStreamingMethodDSL}, |
| 56 | {"service-bidirectional-streaming-no-payload", testdata.BidirectionalStreamingNoPayloadMethodDSL}, |
| 57 | {"service-bidirectional-streaming-result-with-views", testdata.BidirectionalStreamingResultWithViewsMethodDSL}, |
| 58 | {"service-bidirectional-streaming-result-with-explicit-view", testdata.BidirectionalStreamingResultWithExplicitViewMethodDSL}, |
| 59 | {"service-multiple-api-key-security", testdata.MultipleAPIKeySecurityDSL}, |
| 60 | {"service-mixed-and-multiple-api-key-security", testdata.MixedAndMultipleAPIKeySecurityDSL}, |
| 61 | {"service-bearer-security", testdata.BearerSecurityDSL}, |
| 62 | {"service-raw-object-payload-type-name-collision", testdata.RawObjectPayloadTypeNameCollisionDSL}, |
| 63 | } |
| 64 | for _, c := range cases { |
| 65 | t.Run(c.Name, func(t *testing.T) { |
| 66 | root := codegen.RunDSL(t, c.DSL) |
| 67 | services := NewServicesData(root) |
| 68 | require.Len(t, root.Services, 1) |
| 69 | files := Files("goa.design/goa/example", root.Services[0], services, make(map[string][]string)) |
| 70 | require.Greater(t, len(files), 0) |
| 71 | |
| 72 | // Generate the code |
| 73 | buf := new(bytes.Buffer) |
| 74 | for _, s := range files[0].SectionTemplates[1:] { |