Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed Nov 30, 2024
1 parent fd4f252 commit 92cdd80
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 92cdd80

Please sign in to comment.