(t *testing.T)
| 20 | ) |
| 21 | |
| 22 | func TestSections(t *testing.T) { |
| 23 | var ( |
| 24 | goldenPath = filepath.Join("testdata", t.Name()) |
| 25 | ) |
| 26 | cases := []struct { |
| 27 | Name string |
| 28 | DSL func() |
| 29 | }{ |
| 30 | {"empty", testdata.EmptyDSL}, |
| 31 | {"file-service", testdata.FileServiceDSL}, |
| 32 | {"valid", testdata.SimpleDSL}, |
| 33 | {"multiple-services", testdata.MultipleServicesDSL}, |
| 34 | {"multiple-views", testdata.MultipleViewsDSL}, |
| 35 | {"explicit-view", testdata.ExplicitViewDSL}, |
| 36 | {"security", testdata.SecurityDSL}, |
| 37 | {"server-host-with-variables", testdata.ServerHostWithVariablesDSL}, |
| 38 | {"with-spaces", testdata.WithSpacesDSL}, |
| 39 | {"with-map", testdata.WithMapDSL}, |
| 40 | {"with-any", testdata.WithAnyDSL}, |
| 41 | {"path-with-wildcards", testdata.PathWithWildcardDSL}, |
| 42 | {"path-with-multiple-wildcards", testdata.PathWithMultipleWildcardDSL}, |
| 43 | {"path-with-multiple-explicit-wildcards", testdata.PathWithMultipleExplicitWildcardDSL}, |
| 44 | {"headers", testdata.HeadersDSL}, |
| 45 | {"typename", testdata.TypenameDSL}, |
| 46 | {"not-generate-server", testdata.NotGenerateServerDSL}, |
| 47 | {"not-generate-host", testdata.NotGenerateHostDSL}, |
| 48 | {"not-generate-attribute", testdata.NotGenerateAttributeDSL}, |
| 49 | {"json-prefix", testdata.JSONPrefixDSL}, |
| 50 | {"json-indent", testdata.JSONIndentDSL}, |
| 51 | {"json-prefix-indent", testdata.JSONPrefixIndentDSL}, |
| 52 | {"additional-properties-type", testdata.AdditionalPropertiesTypeDSL}, |
| 53 | {"additional-properties-payload-result", testdata.AdditionalPropertiesPayloadResultDSL}, |
| 54 | {"additional-properties-embedded-payload-result", testdata.AdditionalPropertiesPayloadResultDSL}, |
| 55 | } |
| 56 | for _, c := range cases { |
| 57 | t.Run(c.Name, func(t *testing.T) { |
| 58 | // Reset global variables |
| 59 | openapi.Definitions = make(map[string]*openapi.Schema) |
| 60 | root := httpgen.RunHTTPDSL(t, c.DSL) |
| 61 | oFiles, err := openapiv2.Files(root) |
| 62 | if err != nil { |
| 63 | t.Fatalf("OpenAPI failed with %s", err) |
| 64 | } |
| 65 | for i, o := range oFiles { |
| 66 | tname := fmt.Sprintf("file%d", i) |
| 67 | s := o.SectionTemplates |
| 68 | t.Run(tname, func(t *testing.T) { |
| 69 | if len(s) != 1 { |
| 70 | t.Fatalf("expected 1 section, got %d", len(s)) |
| 71 | } |
| 72 | if s[0].Source == "" { |
| 73 | t.Fatalf("empty section template") |
| 74 | } |
| 75 | if s[0].Data == nil { |
| 76 | t.Fatalf("nil data") |
| 77 | } |
| 78 | var buf bytes.Buffer |
| 79 | tmpl := template.Must(template.New("openapi").Funcs(s[0].FuncMap).Parse(s[0].Source)) |
nothing calls this directly
no test coverage detected