-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support passing a schema URI with a fragment as a test target
See: #110 Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
6 changed files
with
232 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$id": "https://example.com", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"definitions": { | ||
"foo": { "type": "string" }, | ||
"bar": { "type": "integer" } | ||
} | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/test.json" | ||
{ | ||
"target": "https://example.com#foo", | ||
"tests": [ | ||
{ | ||
"valid": true, | ||
"data": {} | ||
}, | ||
{ | ||
"valid": true, | ||
"data": { "type": 1 } | ||
} | ||
] | ||
} | ||
EOF | ||
|
||
"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --verbose 1> "$TMP/output.txt" 2>&1 \ | ||
&& CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
Importing schema into the resolution context: $(realpath "$TMP")/schema.json | ||
$(realpath "$TMP")/test.json: | ||
error: Could not resolve schema under test | ||
at https://example.com#foo | ||
EOF | ||
|
||
diff "$TMP/output.txt" "$TMP/expected.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"id": "https://example.com", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"definitions": { | ||
"foo": { "type": "string" }, | ||
"bar": { "type": "integer" } | ||
} | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/test.json" | ||
{ | ||
"target": "https://example.com#/foo", | ||
"tests": [ | ||
{ | ||
"valid": true, | ||
"data": {} | ||
}, | ||
{ | ||
"valid": true, | ||
"data": { "type": 1 } | ||
} | ||
] | ||
} | ||
EOF | ||
|
||
"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --verbose 1> "$TMP/output.txt" 2>&1 \ | ||
&& CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
Importing schema into the resolution context: $(realpath "$TMP")/schema.json | ||
$(realpath "$TMP")/test.json: | ||
error: Could not resolve schema under test | ||
at https://example.com#/foo | ||
EOF | ||
|
||
diff "$TMP/output.txt" "$TMP/expected.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"id": "https://example.com", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"definitions": { | ||
"foo": { "type": "string" }, | ||
"bar": { "type": "integer" } | ||
} | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/test.json" | ||
{ | ||
"target": "https://example.com#/definitions/foo", | ||
"tests": [ | ||
{ | ||
"description": "First test", | ||
"valid": true, | ||
"data": "foo" | ||
}, | ||
{ | ||
"description": "Invalid type", | ||
"valid": false, | ||
"data": 1 | ||
} | ||
] | ||
} | ||
EOF | ||
|
||
"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" 1> "$TMP/output.txt" 2>&1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
$(realpath "$TMP")/test.json: PASS 2/2 | ||
EOF | ||
|
||
diff "$TMP/output.txt" "$TMP/expected.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"id": "https://example.com", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"definitions": { | ||
"foo": { "type": "string" }, | ||
"bar": { "type": "integer" } | ||
} | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/test.json" | ||
{ | ||
"target": "https://example.com#/definitions/foo", | ||
"tests": [ | ||
{ | ||
"description": "First test", | ||
"valid": true, | ||
"data": "foo" | ||
}, | ||
{ | ||
"description": "Invalid type", | ||
"valid": false, | ||
"data": 1 | ||
} | ||
] | ||
} | ||
EOF | ||
|
||
"$1" test "$TMP/test.json" --resolve "$TMP/schema.json" --verbose 1> "$TMP/output.txt" 2>&1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
Importing schema into the resolution context: $(realpath "$TMP")/schema.json | ||
$(realpath "$TMP")/test.json: | ||
1/2 PASS First test | ||
2/2 PASS Invalid type | ||
EOF | ||
|
||
diff "$TMP/output.txt" "$TMP/expected.txt" |