(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestExampleCLIFiles(t *testing.T) { |
| 18 | cases := []struct { |
| 19 | Name string |
| 20 | DSL func() |
| 21 | PkgPath string |
| 22 | }{ |
| 23 | {"no-server", ctestdata.NoServerDSL, ""}, |
| 24 | {"server-hosting-service-subset", ctestdata.ServerHostingServiceSubsetDSL, ""}, |
| 25 | {"server-hosting-multiple-services", ctestdata.ServerHostingMultipleServicesDSL, ""}, |
| 26 | {"no-server-pkgpath", ctestdata.NoServerDSL, "my/pkg/path"}, |
| 27 | {"server-hosting-service-subset-pkgpath", ctestdata.ServerHostingServiceSubsetDSL, "my/pkg/path"}, |
| 28 | {"server-hosting-multiple-services-pkgpath", ctestdata.ServerHostingMultipleServicesDSL, "my/pkg/path"}, |
| 29 | {"interceptors", testdata.InterceptorsDSL, ""}, |
| 30 | } |
| 31 | for _, c := range cases { |
| 32 | t.Run(c.Name, func(t *testing.T) { |
| 33 | // reset global variable |
| 34 | example.Servers = make(example.ServersData) |
| 35 | root := codegen.RunDSL(t, c.DSL) |
| 36 | services := NewServicesData(service.NewServicesData(root)) |
| 37 | fs := ExampleCLIFiles(c.PkgPath, services) |
| 38 | require.Greater(t, len(fs), 0) |
| 39 | require.Greater(t, len(fs[0].SectionTemplates), 0) |
| 40 | var buf bytes.Buffer |
| 41 | for _, s := range fs[0].SectionTemplates { |
| 42 | require.NoError(t, s.Write(&buf)) |
| 43 | } |
| 44 | code := codegen.FormatTestCode(t, buf.String()) |
| 45 | golden := filepath.Join("testdata", "client-"+c.Name+".golden") |
| 46 | testutil.AssertGo(t, golden, code) |
| 47 | }) |
| 48 | } |
| 49 | } |
nothing calls this directly
no test coverage detected