Skip to content

Commit

Permalink
add test validating schema with gojsonschema
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Feb 10, 2025
1 parent 2e2665b commit f9053d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion schema/compose-spec.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "compose_spec.json",
"type": "object",
"title": "Compose Specification",
Expand Down
13 changes: 13 additions & 0 deletions schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package schema

import (
"os"
"path/filepath"
"testing"

"github.com/xeipuuv/gojsonschema"
"gopkg.in/yaml.v3"
"gotest.tools/v3/assert"
)
Expand Down Expand Up @@ -251,3 +253,14 @@ func TestValidateVariables(t *testing.T) {
assert.NilError(t, err)
assert.NilError(t, Validate(config))
}

func TestSchema(t *testing.T) {
abs, err := filepath.Abs("compose-spec.json")
assert.NilError(t, err)
schema := gojsonschema.NewReferenceLoader("file:///" + abs)
sl := gojsonschema.NewSchemaLoader()
sl.Draft = gojsonschema.Draft7
sl.Validate = true
_, err = sl.Compile(schema)
assert.NilError(t, err)
}

0 comments on commit f9053d8

Please sign in to comment.