@@ -39,7 +39,14 @@ type schemaTestT struct {
39
39
}
40
40
}
41
41
42
+ type schemasTestT struct {
43
+ Schema * spec.Schema `json:"schema"`
44
+ Valid interface {} `json:"valid"`
45
+ Invalid interface {} `json:"invalid"`
46
+ }
47
+
42
48
var jsonSchemaFixturesPath = filepath .Join ("fixtures" , "jsonschema_suite" )
49
+ var schemaFixturesPath = filepath .Join ("fixtures" , "schemas" )
43
50
44
51
var ints = []interface {}{
45
52
1 ,
@@ -164,3 +171,41 @@ func TestJSONSchemaSuite(t *testing.T) {
164
171
}
165
172
}
166
173
}
174
+
175
+ func TestSchemaFixtures (t * testing.T ) {
176
+ files , err := ioutil .ReadDir (schemaFixturesPath )
177
+ if err != nil {
178
+ t .Fatal (err )
179
+ }
180
+
181
+ for _ , f := range files {
182
+ if f .IsDir () {
183
+ continue
184
+ }
185
+ fileName := f .Name ()
186
+ specName := strings .TrimSuffix (fileName , filepath .Ext (fileName ))
187
+
188
+ t .Log ("Running " + specName )
189
+ b , _ := ioutil .ReadFile (filepath .Join (schemaFixturesPath , fileName ))
190
+
191
+ var testDescriptions []schemasTestT
192
+ json .Unmarshal (b , & testDescriptions )
193
+
194
+ for _ , testDescription := range testDescriptions {
195
+
196
+ err := spec .ExpandSchema (testDescription .Schema , nil , nil /*new(noopResCache)*/ )
197
+ if assert .NoError (t , err ) {
198
+
199
+ validator := NewSchemaValidator (testDescription .Schema , nil , "data" , strfmt .Default )
200
+ valid := validator .Validate (testDescription .Valid )
201
+ if assert .NotNil (t , valid , specName + " should validate" ) {
202
+ assert .Empty (t , valid .Errors , specName + ".valid should not have errors" )
203
+ }
204
+ invalid := validator .Validate (testDescription .Invalid )
205
+ if assert .NotNil (t , invalid , specName + " should validate" ) {
206
+ assert .NotEmpty (t , invalid .Errors , specName + ".invalid should have errors" )
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
0 commit comments