MCPcopy Create free account
hub / github.com/goadesign/goa / TestExtensions

Function TestExtensions

http/codegen/openapi/v2/files_test.go:147–189  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestExtensions(t *testing.T) {
148 var (
149 goldenPath = filepath.Join("testdata", t.Name())
150 )
151 cases := []struct {
152 Name string
153 DSL func()
154 }{
155 {"endpoint", testdata.ExtensionDSL},
156 }
157 for _, c := range cases {
158 t.Run(c.Name, func(t *testing.T) {
159 // Reset global variables
160 openapi.Definitions = make(map[string]*openapi.Schema)
161 root := httpgen.RunHTTPDSL(t, c.DSL)
162 oFiles, err := openapiv2.Files(root)
163 require.NoError(t, err, "OpenAPI failed")
164 require.NotEmpty(t, oFiles, "No swagger files")
165 for i, o := range oFiles {
166 tname := fmt.Sprintf("file%d", i)
167 s := o.SectionTemplates
168 t.Run(tname, func(t *testing.T) {
169 require.Len(t, s, 1, "expected 1 section, got %d", len(s))
170 require.NotEmpty(t, s[0].Source, "empty section template")
171 require.NotNil(t, s[0].Data, "nil data")
172 var buf bytes.Buffer
173 tmpl := template.Must(template.New("openapi").Funcs(s[0].FuncMap).Parse(s[0].Source))
174 require.NoError(t, tmpl.Execute(&buf, s[0].Data), "failed to render template")
175 if filepath.Ext(o.Path) == ".json" {
176 require.NoError(t, validateSwagger(buf.Bytes()), "invalid swagger")
177 }
178
179 golden := filepath.Join(goldenPath, fmt.Sprintf("%s_%s.golden", c.Name, tname))
180 if filepath.Ext(o.Path) == ".json" {
181 testutil.AssertJSON(t, golden, buf.Bytes())
182 } else {
183 testutil.AssertString(t, golden, buf.String())
184 }
185 })
186 }
187 })
188 }
189}
190
191func TestNamedPrimitiveParamsAndHeadersUseOpenAPIBaseTypes(t *testing.T) {
192 // Reset global variables

Callers

nothing calls this directly

Calls 7

AssertJSONFunction · 0.92
AssertStringFunction · 0.92
ExecuteMethod · 0.80
validateSwaggerFunction · 0.70
NameMethod · 0.65
StringMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected