-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase test coverage of the
bundle
command
Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
27 changed files
with
568 additions
and
85 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
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,19 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
"$1" bundle 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << 'EOF' > "$TMP/expected.txt" | ||
error: This command expects a path to a schema. For example: | ||
jsonschema bundle path/to/schema.json | ||
EOF | ||
|
||
diff "$TMP/stderr.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,26 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "https://example.com", | ||
"$ref": "nested" | ||
} | ||
EOF | ||
|
||
"$1" bundle "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
error: Could not resolve the requested schema | ||
at https://example.com/nested | ||
EOF | ||
|
||
diff "$TMP/stderr.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,46 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "https://example.com", | ||
"$ref": "nested" | ||
} | ||
EOF | ||
|
||
mkdir "$TMP/schemas" | ||
|
||
cat << 'EOF' > "$TMP/schemas/remote.json" | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "https://example.com/nested", | ||
"type": "string" | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/schemas/duplicated.json" | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "https://example.com/nested", | ||
"type": "number" | ||
} | ||
EOF | ||
|
||
"$1" bundle "$TMP/schema.json" \ | ||
--resolve "$TMP/schemas" 2>"$TMP/stderr.txt" \ | ||
&& CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
error: Cannot register the same identifier twice: https://example.com/nested | ||
EOF | ||
|
||
diff "$TMP/stderr.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,32 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "https://example.com", | ||
"$ref": "nested" | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/invalid.json" | ||
{ xxx } | ||
EOF | ||
|
||
"$1" bundle "$TMP/schema.json" \ | ||
--resolve "$TMP/invalid.json" 2>"$TMP/stderr.txt" \ | ||
&& CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
error: Failed to parse the JSON document at line 1 and column 3 | ||
$(realpath "$TMP")/invalid.json | ||
EOF | ||
|
||
diff "$TMP/stderr.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,25 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"type" string | ||
} | ||
EOF | ||
|
||
"$1" bundle "$TMP/schema.json" 2>"$TMP/stderr.txt" \ | ||
&& CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
error: Failed to parse the JSON document at line 2 and column 10 | ||
$(realpath "$TMP")/schema.json | ||
EOF | ||
|
||
diff "$TMP/stderr.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,26 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "https://example.com/unknown", | ||
"$id": "https://example.com", | ||
"$ref": "nested" | ||
} | ||
EOF | ||
|
||
"$1" bundle "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
error: Could not resolve the requested schema | ||
at https://example.com/unknown | ||
EOF | ||
|
||
diff "$TMP/stderr.txt" "$TMP/expected.txt" |
File renamed without changes.
File renamed without changes.
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" | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "https://example.com", | ||
"$ref": "nested" | ||
} | ||
EOF | ||
|
||
mkdir "$TMP/schemas" | ||
cat << 'EOF' > "$TMP/schemas/remote.json" | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"$id": "https://example.com/nested", | ||
"type": "string" | ||
} | ||
EOF | ||
|
||
"$1" bundle "$TMP/schema.json" --resolve "$TMP/schemas" --verbose 1> "$TMP/result.json" 2>&1 | ||
|
||
cat << EOF > "$TMP/expected.json" | ||
Importing schema into the resolution context: $(realpath "$TMP")/schemas/remote.json | ||
{ | ||
"\$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"\$id": "https://example.com", | ||
"\$ref": "nested", | ||
"\$defs": { | ||
"https://example.com/nested": { | ||
"\$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"\$id": "https://example.com/nested", | ||
"type": "string" | ||
} | ||
} | ||
} | ||
EOF | ||
|
||
diff "$TMP/result.json" "$TMP/expected.json" |
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,77 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "https://example.com/meta", | ||
"$id": "https://example.com", | ||
"$ref": "nested" | ||
} | ||
EOF | ||
|
||
mkdir "$TMP/schemas" | ||
|
||
cat << 'EOF' > "$TMP/schemas/meta.json" | ||
{ | ||
"$schema": "https://json-schema.org/draft/2019-09/schema", | ||
"$id": "https://example.com/meta", | ||
"$vocabulary": { | ||
"https://json-schema.org/draft/2019-09/vocab/core": true, | ||
"https://json-schema.org/draft/2019-09/vocab/applicator": true, | ||
"https://json-schema.org/draft/2019-09/vocab/validation": true, | ||
"https://json-schema.org/draft/2019-09/vocab/meta-data": true, | ||
"https://json-schema.org/draft/2019-09/vocab/format": false, | ||
"https://json-schema.org/draft/2019-09/vocab/content": true | ||
}, | ||
"$ref": "https://json-schema.org/draft/2019-09/schema" | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/schemas/remote.json" | ||
{ | ||
"$schema": "https://json-schema.org/draft/2019-09/schema", | ||
"$id": "https://example.com/nested", | ||
"type": "string" | ||
} | ||
EOF | ||
|
||
"$1" bundle "$TMP/schema.json" --resolve "$TMP/schemas" > "$TMP/result.json" | ||
|
||
cat << 'EOF' > "$TMP/expected.json" | ||
{ | ||
"$schema": "https://example.com/meta", | ||
"$id": "https://example.com", | ||
"$ref": "nested", | ||
"$defs": { | ||
"https://example.com/nested": { | ||
"$schema": "https://json-schema.org/draft/2019-09/schema", | ||
"$id": "https://example.com/nested", | ||
"type": "string" | ||
}, | ||
"https://example.com/meta": { | ||
"$schema": "https://json-schema.org/draft/2019-09/schema", | ||
"$id": "https://example.com/meta", | ||
"$vocabulary": { | ||
"https://json-schema.org/draft/2019-09/vocab/core": true, | ||
"https://json-schema.org/draft/2019-09/vocab/applicator": true, | ||
"https://json-schema.org/draft/2019-09/vocab/validation": true, | ||
"https://json-schema.org/draft/2019-09/vocab/meta-data": true, | ||
"https://json-schema.org/draft/2019-09/vocab/format": false, | ||
"https://json-schema.org/draft/2019-09/vocab/content": true | ||
}, | ||
"$ref": "https://json-schema.org/draft/2019-09/schema" | ||
} | ||
} | ||
} | ||
EOF | ||
|
||
diff "$TMP/result.json" "$TMP/expected.json" | ||
|
||
# Must come out formatted | ||
"$1" fmt "$TMP/result.json" --check |
File renamed without changes.
Oops, something went wrong.