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

Function TestValidations

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

Source from the content-addressed store, hash-verified

99}
100
101func TestValidations(t *testing.T) {
102 var (
103 goldenPath = filepath.Join("testdata", t.Name())
104 )
105 cases := []struct {
106 Name string
107 DSL func()
108 }{
109 {"string", testdata.StringValidationDSL},
110 {"integer", testdata.IntValidationDSL},
111 {"array", testdata.ArrayValidationDSL},
112 }
113 for _, c := range cases {
114 t.Run(c.Name, func(t *testing.T) {
115 // Reset global variables
116 openapi.Definitions = make(map[string]*openapi.Schema)
117 root := httpgen.RunHTTPDSL(t, c.DSL)
118 oFiles, err := openapiv2.Files(root)
119 require.NoError(t, err, "OpenAPI failed")
120 require.NotEmpty(t, oFiles, "No swagger files")
121 for i, o := range oFiles {
122 tname := fmt.Sprintf("file%d", i)
123 s := o.SectionTemplates
124 t.Run(tname, func(t *testing.T) {
125 require.Len(t, s, 1, "expected 1 section, got %d", len(s))
126 require.NotEmpty(t, s[0].Source, "empty section template")
127 require.NotNil(t, s[0].Data, "nil data")
128 var buf bytes.Buffer
129 tmpl := template.Must(template.New("openapi").Funcs(s[0].FuncMap).Parse(s[0].Source))
130 require.NoError(t, tmpl.Execute(&buf, s[0].Data), "failed to render template")
131 if filepath.Ext(o.Path) == ".json" {
132 require.NoError(t, validateSwagger(buf.Bytes()), "invalid swagger")
133 }
134
135 golden := filepath.Join(goldenPath, fmt.Sprintf("%s_%s.golden", c.Name, tname))
136 if filepath.Ext(o.Path) == ".json" {
137 testutil.AssertJSON(t, golden, buf.Bytes())
138 } else {
139 testutil.AssertString(t, golden, buf.String())
140 }
141 })
142 }
143 })
144 }
145}
146
147func TestExtensions(t *testing.T) {
148 var (

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