diff --git a/tests/schema/schema_test.go b/tests/schema/schema_test.go index 4f125519..53dc9671 100644 --- a/tests/schema/schema_test.go +++ b/tests/schema/schema_test.go @@ -13,11 +13,15 @@ import ( "github.com/xeipuuv/gojsonschema" ) -func TestJsonSchema(t *testing.T) { +func loadUncorsSchema(t *testing.T) gojsonschema.JSONLoader { jsonSchemaPath := filepath.Join(testutils.CurrentDir(t), "../../schema.json") + return gojsonschema.NewReferenceLoader("file://" + jsonSchemaPath) +} + +func TestJsonSchema(t *testing.T) { schemaLoader := gojsonschema.NewReferenceLoader("http://json-schema.org/draft-07/schema#") - documentLoader := gojsonschema.NewReferenceLoader("file://" + jsonSchemaPath) + documentLoader := loadUncorsSchema(t) result, err := gojsonschema.Validate(schemaLoader, documentLoader) require.NoError(t, err) @@ -27,14 +31,12 @@ func TestJsonSchema(t *testing.T) { func TestInvalidJsonSchema(t *testing.T) { testCases := schema.LoadTestCasesWithErrors(t, testutils.CurrentDir(t), "invalid") - - jsonSchemaPath := filepath.Join(testutils.CurrentDir(t), "../../schema.json") + schemaLoader := loadUncorsSchema(t) for _, testCase := range testCases { t.Run(testCase.Name, func(t *testing.T) { targetJSONFile := schema.TransformToJSON(t, testCase.File) - schemaLoader := gojsonschema.NewReferenceLoader("file://" + jsonSchemaPath) documentLoader := gojsonschema.NewReferenceLoader("file://" + targetJSONFile) result, err := gojsonschema.Validate(schemaLoader, documentLoader) @@ -51,14 +53,12 @@ func TestInvalidJsonSchema(t *testing.T) { func TestValidJsonSchema(t *testing.T) { testCases := schema.LoadTestCases(t, testutils.CurrentDir(t), "valid") - - jsonSchemaPath := filepath.Join(testutils.CurrentDir(t), "../../schema.json") + schemaLoader := loadUncorsSchema(t) for _, testCase := range testCases { t.Run(testCase.Name, func(t *testing.T) { targetJSONFile := schema.TransformToJSON(t, testCase.File) - schemaLoader := gojsonschema.NewReferenceLoader("file://" + jsonSchemaPath) documentLoader := gojsonschema.NewReferenceLoader("file://" + targetJSONFile) result, err := gojsonschema.Validate(schemaLoader, documentLoader)