(t *testing.T)
| 39 | } |
| 40 | |
| 41 | func TestExampleServerFiles(t *testing.T) { |
| 42 | cases := []struct { |
| 43 | Name string |
| 44 | DSL func() |
| 45 | }{ |
| 46 | {"no-server", testdata.NoServerDSL}, |
| 47 | {"same-api-service-name", testdata.SameAPIServiceNameDSL}, |
| 48 | {"single-server-single-host", testdata.SingleServerSingleHostDSL}, |
| 49 | {"single-server-single-host-with-variables", testdata.SingleServerSingleHostWithVariablesDSL}, |
| 50 | {"server-hosting-service-with-file-server", testdata.ServerHostingServiceWithFileServerDSL}, |
| 51 | {"server-hosting-service-subset", testdata.ServerHostingServiceSubsetDSL}, |
| 52 | {"server-hosting-multiple-services", testdata.ServerHostingMultipleServicesDSL}, |
| 53 | {"single-server-multiple-hosts", testdata.SingleServerMultipleHostsDSL}, |
| 54 | {"single-server-multiple-hosts-with-variables", testdata.SingleServerMultipleHostsWithVariablesDSL}, |
| 55 | {"service-name-with-spaces", testdata.NamesWithSpacesDSL}, |
| 56 | {"service-for-only-http", testdata.ServiceForOnlyHTTPDSL}, |
| 57 | {"sercice-for-only-grpc", testdata.ServiceForOnlyGRPCDSL}, |
| 58 | {"service-for-http-and-part-of-grpc", testdata.ServiceForHTTPAndPartOfGRPCDSL}, |
| 59 | } |
| 60 | for _, c := range cases { |
| 61 | t.Run(c.Name, func(t *testing.T) { |
| 62 | Servers = make(ServersData) |
| 63 | root := codegen.RunDSL(t, c.DSL) |
| 64 | services := service.NewServicesData(root) |
| 65 | fs := ServerFiles("", root, services) |
| 66 | require.Len(t, fs, 1) |
| 67 | require.Greater(t, len(fs[0].SectionTemplates), 0) |
| 68 | var buf bytes.Buffer |
| 69 | for _, s := range fs[0].SectionTemplates[1:] { |
| 70 | require.NoError(t, s.Write(&buf)) |
| 71 | } |
| 72 | code := codegen.FormatTestCode(t, "package foo\n"+buf.String()) |
| 73 | golden := filepath.Join("testdata", "server-"+c.Name+".golden") |
| 74 | compareOrUpdateGolden(t, code, golden) |
| 75 | }) |
| 76 | } |
| 77 | } |
nothing calls this directly
no test coverage detected