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