From fcc1749194f5732051aeb790ce067bb2aba8cee7 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 12 Jul 2024 17:15:59 +0100 Subject: [PATCH] Increase test coverage of the `bundle` command Signed-off-by: Juan Cruz Viotti --- src/command_bundle.cc | 9 ++- src/command_validate.cc | 5 +- src/main.cc | 3 + test/CMakeLists.txt | 29 +++++-- test/bundle/fail_no_schema.sh | 19 +++++ .../fail_relative_external_ref_missing.sh | 26 +++++++ test/bundle/fail_resolve_duplicate.sh | 46 +++++++++++ test/bundle/fail_resolve_invalid_json.sh | 32 ++++++++ test/bundle/fail_schema_invalid_json.sh | 25 ++++++ test/bundle/fail_unknown_metaschema.sh | 26 +++++++ .../pass_into_resolve_directory.sh} | 0 .../pass_resolve_directory.sh} | 0 test/bundle/pass_resolve_directory_verbose.sh | 45 +++++++++++ test/bundle/pass_resolve_metaschema.sh | 77 +++++++++++++++++++ .../pass_resolve_single.sh} | 0 test/bundle/pass_resolve_with_ignore.sh | 56 ++++++++++++++ .../pass_without_id.sh} | 0 test/bundle/pass_without_id_verbose.sh | 44 +++++++++++ .../pass_without_remote.sh} | 0 test/bundle_remote_no_http.sh | 26 ------- test/ci/bundle_remote_http.sh | 46 ----------- test/ci/fail_bundle_http_non_200.sh | 26 +++++++ test/ci/fail_bundle_http_non_200_verbose.sh | 27 +++++++ test/ci/fail_bundle_http_non_schema.sh | 26 +++++++ .../ci/fail_bundle_http_non_schema_verbose.sh | 27 +++++++ test/ci/pass_bundle_http.sh | 29 +++++++ test/validate/fail_no_schema.sh | 4 +- 27 files changed, 568 insertions(+), 85 deletions(-) create mode 100755 test/bundle/fail_no_schema.sh create mode 100755 test/bundle/fail_relative_external_ref_missing.sh create mode 100755 test/bundle/fail_resolve_duplicate.sh create mode 100755 test/bundle/fail_resolve_invalid_json.sh create mode 100755 test/bundle/fail_schema_invalid_json.sh create mode 100755 test/bundle/fail_unknown_metaschema.sh rename test/{bundle_into_resolve_directory.sh => bundle/pass_into_resolve_directory.sh} (100%) rename test/{bundle_remote_directory.sh => bundle/pass_resolve_directory.sh} (100%) create mode 100755 test/bundle/pass_resolve_directory_verbose.sh create mode 100755 test/bundle/pass_resolve_metaschema.sh rename test/{bundle_remote_single_schema.sh => bundle/pass_resolve_single.sh} (100%) create mode 100755 test/bundle/pass_resolve_with_ignore.sh rename test/{bundle_remote_directory_without_id.sh => bundle/pass_without_id.sh} (100%) create mode 100755 test/bundle/pass_without_id_verbose.sh rename test/{bundle_non_remote.sh => bundle/pass_without_remote.sh} (100%) delete mode 100755 test/bundle_remote_no_http.sh delete mode 100755 test/ci/bundle_remote_http.sh create mode 100755 test/ci/fail_bundle_http_non_200.sh create mode 100755 test/ci/fail_bundle_http_non_200_verbose.sh create mode 100755 test/ci/fail_bundle_http_non_schema.sh create mode 100755 test/ci/fail_bundle_http_non_schema_verbose.sh create mode 100755 test/ci/pass_bundle_http.sh diff --git a/src/command_bundle.cc b/src/command_bundle.cc index 4f67abc5..fabfc2fd 100644 --- a/src/command_bundle.cc +++ b/src/command_bundle.cc @@ -11,7 +11,14 @@ auto intelligence::jsonschema::cli::bundle( const std::span &arguments) -> int { const auto options{ parse_options(arguments, {"h", "http", "w", "without-id"})}; - CLI_ENSURE(!options.at("").empty(), "You must pass a JSON Schema as input"); + + if (options.at("").size() < 1) { + std::cerr + << "error: This command expects a path to a schema. For example:\n\n" + << " jsonschema bundle path/to/schema.json\n"; + return EXIT_FAILURE; + } + auto schema{sourcemeta::jsontoolkit::from_file(options.at("").front())}; if (options.contains("w") || options.contains("without-id")) { diff --git a/src/command_validate.cc b/src/command_validate.cc index c2b4b9bb..ec941b13 100644 --- a/src/command_validate.cc +++ b/src/command_validate.cc @@ -17,9 +17,8 @@ auto intelligence::jsonschema::cli::validate( if (options.at("").size() < 1) { std::cerr - << "error: This command expects to pass a path to a schema and a\n" - << "path to an instance to validate against the schema. For " - "example:\n\n" + << "error: This command expects a path to a schema and a path to an\n" + << "instance to validate against the schema. For example:\n\n" << " jsonschema validate path/to/schema.json path/to/instance.json\n"; return EXIT_FAILURE; } diff --git a/src/main.cc b/src/main.cc index 787d4683..91cdbf21 100644 --- a/src/main.cc +++ b/src/main.cc @@ -103,6 +103,9 @@ auto main(int argc, char *argv[]) noexcept -> int { } catch (const sourcemeta::jsontoolkit::SchemaResolutionError &error) { std::cerr << "error: " << error.what() << "\n at " << error.id() << "\n"; return EXIT_FAILURE; + } catch (const sourcemeta::jsontoolkit::SchemaError &error) { + std::cerr << "error: " << error.what() << "\n"; + return EXIT_FAILURE; } catch (const sourcemeta::jsontoolkit::SchemaVocabularyError &error) { std::cerr << "error: " << error.what() << "\n " << error.uri() << "\n\nTo request support for it, please open an issue " diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1d216e39..4ad92a87 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,12 +26,6 @@ add_jsonschema_test_unix(format_directory_ignore_directory) add_jsonschema_test_unix(format_directory_ignore_file) add_jsonschema_test_unix(format_check_single_invalid) add_jsonschema_test_unix(frame) -add_jsonschema_test_unix(bundle_non_remote) -add_jsonschema_test_unix(bundle_into_resolve_directory) -add_jsonschema_test_unix(bundle_remote_single_schema) -add_jsonschema_test_unix(bundle_remote_no_http) -add_jsonschema_test_unix(bundle_remote_directory) -add_jsonschema_test_unix(bundle_remote_directory_without_id) add_jsonschema_test_unix(lint_pass) add_jsonschema_test_unix(lint_fail) add_jsonschema_test_unix(lint_fix) @@ -98,8 +92,29 @@ add_jsonschema_test_unix(test/pass_single_no_test_description_verbose) add_jsonschema_test_unix(test/pass_multi_directory_resolve) add_jsonschema_test_unix(test/pass_multi_directory_resolve_verbose) +# Bundle +add_jsonschema_test_unix(bundle/pass_into_resolve_directory) +add_jsonschema_test_unix(bundle/pass_resolve_directory) +add_jsonschema_test_unix(bundle/pass_resolve_directory_verbose) +add_jsonschema_test_unix(bundle/pass_resolve_metaschema) +add_jsonschema_test_unix(bundle/pass_resolve_single) +add_jsonschema_test_unix(bundle/pass_resolve_with_ignore) +add_jsonschema_test_unix(bundle/pass_without_id) +add_jsonschema_test_unix(bundle/pass_without_id_verbose) +add_jsonschema_test_unix(bundle/pass_without_remote) +add_jsonschema_test_unix(bundle/fail_no_schema) +add_jsonschema_test_unix(bundle/fail_relative_external_ref_missing) +add_jsonschema_test_unix(bundle/fail_resolve_duplicate) +add_jsonschema_test_unix(bundle/fail_resolve_invalid_json) +add_jsonschema_test_unix(bundle/fail_schema_invalid_json) +add_jsonschema_test_unix(bundle/fail_unknown_metaschema) + # CI specific tests -add_jsonschema_test_unix_ci(bundle_remote_http) +add_jsonschema_test_unix_ci(pass_bundle_http) +add_jsonschema_test_unix_ci(fail_bundle_http_non_200) +add_jsonschema_test_unix_ci(fail_bundle_http_non_200_verbose) +add_jsonschema_test_unix_ci(fail_bundle_http_non_schema) +add_jsonschema_test_unix_ci(fail_bundle_http_non_schema_verbose) add_jsonschema_test_unix_ci(fail_validate_http_non_200) add_jsonschema_test_unix_ci(fail_validate_http_non_200_verbose) add_jsonschema_test_unix_ci(fail_validate_http_non_schema) diff --git a/test/bundle/fail_no_schema.sh b/test/bundle/fail_no_schema.sh new file mode 100755 index 00000000..c7b8adf8 --- /dev/null +++ b/test/bundle/fail_no_schema.sh @@ -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" diff --git a/test/bundle/fail_relative_external_ref_missing.sh b/test/bundle/fail_relative_external_ref_missing.sh new file mode 100755 index 00000000..df1f7543 --- /dev/null +++ b/test/bundle/fail_relative_external_ref_missing.sh @@ -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" diff --git a/test/bundle/fail_resolve_duplicate.sh b/test/bundle/fail_resolve_duplicate.sh new file mode 100755 index 00000000..fa44de03 --- /dev/null +++ b/test/bundle/fail_resolve_duplicate.sh @@ -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" + diff --git a/test/bundle/fail_resolve_invalid_json.sh b/test/bundle/fail_resolve_invalid_json.sh new file mode 100755 index 00000000..39ad209f --- /dev/null +++ b/test/bundle/fail_resolve_invalid_json.sh @@ -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" diff --git a/test/bundle/fail_schema_invalid_json.sh b/test/bundle/fail_schema_invalid_json.sh new file mode 100755 index 00000000..8d971dee --- /dev/null +++ b/test/bundle/fail_schema_invalid_json.sh @@ -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" diff --git a/test/bundle/fail_unknown_metaschema.sh b/test/bundle/fail_unknown_metaschema.sh new file mode 100755 index 00000000..56858dcd --- /dev/null +++ b/test/bundle/fail_unknown_metaschema.sh @@ -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" diff --git a/test/bundle_into_resolve_directory.sh b/test/bundle/pass_into_resolve_directory.sh similarity index 100% rename from test/bundle_into_resolve_directory.sh rename to test/bundle/pass_into_resolve_directory.sh diff --git a/test/bundle_remote_directory.sh b/test/bundle/pass_resolve_directory.sh similarity index 100% rename from test/bundle_remote_directory.sh rename to test/bundle/pass_resolve_directory.sh diff --git a/test/bundle/pass_resolve_directory_verbose.sh b/test/bundle/pass_resolve_directory_verbose.sh new file mode 100755 index 00000000..93627dad --- /dev/null +++ b/test/bundle/pass_resolve_directory_verbose.sh @@ -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" diff --git a/test/bundle/pass_resolve_metaschema.sh b/test/bundle/pass_resolve_metaschema.sh new file mode 100755 index 00000000..48c2af3a --- /dev/null +++ b/test/bundle/pass_resolve_metaschema.sh @@ -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 diff --git a/test/bundle_remote_single_schema.sh b/test/bundle/pass_resolve_single.sh similarity index 100% rename from test/bundle_remote_single_schema.sh rename to test/bundle/pass_resolve_single.sh diff --git a/test/bundle/pass_resolve_with_ignore.sh b/test/bundle/pass_resolve_with_ignore.sh new file mode 100755 index 00000000..7a258bb0 --- /dev/null +++ b/test/bundle/pass_resolve_with_ignore.sh @@ -0,0 +1,56 @@ +#!/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" --ignore "$TMP/schemas/duplicated.json" > "$TMP/result.json" + +cat << 'EOF' > "$TMP/expected.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" + +# Must come out formatted +"$1" fmt "$TMP/result.json" --check diff --git a/test/bundle_remote_directory_without_id.sh b/test/bundle/pass_without_id.sh similarity index 100% rename from test/bundle_remote_directory_without_id.sh rename to test/bundle/pass_without_id.sh diff --git a/test/bundle/pass_without_id_verbose.sh b/test/bundle/pass_without_id_verbose.sh new file mode 100755 index 00000000..4a59c75e --- /dev/null +++ b/test/bundle/pass_without_id_verbose.sh @@ -0,0 +1,44 @@ +#!/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" --without-id --verbose 1> "$TMP/result.json" 2>&1 + +cat << EOF > "$TMP/expected.json" +Bundling without using identifiers +Importing schema into the resolution context: $(realpath "$TMP")/schemas/remote.json +{ + "\$schema": "https://json-schema.org/draft/2020-12/schema", + "\$ref": "#/\$defs/https%3A~1~1example.com~1nested", + "\$defs": { + "https://example.com/nested": { + "\$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string" + } + } +} +EOF + +diff "$TMP/result.json" "$TMP/expected.json" diff --git a/test/bundle_non_remote.sh b/test/bundle/pass_without_remote.sh similarity index 100% rename from test/bundle_non_remote.sh rename to test/bundle/pass_without_remote.sh diff --git a/test/bundle_remote_no_http.sh b/test/bundle_remote_no_http.sh deleted file mode 100755 index d96b8e9b..00000000 --- a/test/bundle_remote_no_http.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/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" && CODE="$?" || CODE="$?" - -if [ "$CODE" = "0" ] -then - echo "FAIL" 1>&2 - exit 1 -else - echo "PASS" 1>&2 -fi diff --git a/test/ci/bundle_remote_http.sh b/test/ci/bundle_remote_http.sh deleted file mode 100755 index c92534f2..00000000 --- a/test/ci/bundle_remote_http.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/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", - "$ref": "https://json-schema.org/draft/2020-12/meta/format-annotation" -} -EOF - -"$1" bundle "$TMP/schema.json" --http > "$TMP/result.json" - -cat << 'EOF' > "$TMP/expected.json" -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://json-schema.org/draft/2020-12/meta/format-annotation", - "$defs": { - "https://json-schema.org/draft/2020-12/meta/format-annotation": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://json-schema.org/draft/2020-12/meta/format-annotation", - "$vocabulary": { - "https://json-schema.org/draft/2020-12/vocab/format-annotation": true - }, - "$dynamicAnchor": "meta", - "title": "Format vocabulary meta-schema for annotation results", - "type": [ - "object", - "boolean" - ], - "properties": { - "format": { - "type": "string" - } - } - } - } -} -EOF - -diff "$TMP/result.json" "$TMP/expected.json" diff --git a/test/ci/fail_bundle_http_non_200.sh b/test/ci/fail_bundle_http_non_200.sh new file mode 100755 index 00000000..92046c36 --- /dev/null +++ b/test/ci/fail_bundle_http_non_200.sh @@ -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": "http://json-schema.org/draft-07/schema#", + "allOf": [ { "$ref": "https://example.com" } ] +} +EOF + +"$1" bundle "$TMP/schema.json" --http 2> "$TMP/stderr.txt" \ + && CODE="$?" || CODE="$?" +test "$CODE" = "1" || exit 1 + +cat << EOF > "$TMP/expected.txt" +error: 400 Bad Request + at https://example.com +EOF + +diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/ci/fail_bundle_http_non_200_verbose.sh b/test/ci/fail_bundle_http_non_200_verbose.sh new file mode 100755 index 00000000..c31d1e85 --- /dev/null +++ b/test/ci/fail_bundle_http_non_200_verbose.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +TMP="$(mktemp -d)" +clean() { rm -rf "$TMP"; } +trap clean EXIT + +cat << 'EOF' > "$TMP/schema.json" +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "allOf": [ { "$ref": "https://example.com" } ] +} +EOF + +"$1" bundle "$TMP/schema.json" --http --verbose 2> "$TMP/stderr.txt" \ + && CODE="$?" || CODE="$?" +test "$CODE" = "1" || exit 1 + +cat << EOF > "$TMP/expected.txt" +Resolving over HTTP: https://example.com +error: 400 Bad Request + at https://example.com +EOF + +diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/ci/fail_bundle_http_non_schema.sh b/test/ci/fail_bundle_http_non_schema.sh new file mode 100755 index 00000000..72bc9417 --- /dev/null +++ b/test/ci/fail_bundle_http_non_schema.sh @@ -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": "http://json-schema.org/draft-07/schema#", + "allOf": [ { "$ref": "https://jsonplaceholder.typicode.com/todos/1" } ] +} +EOF + +"$1" bundle "$TMP/schema.json" --http 2> "$TMP/stderr.txt" \ + && CODE="$?" || CODE="$?" +test "$CODE" = "1" || exit 1 + +cat << EOF > "$TMP/expected.txt" +error: The JSON document is not a valid JSON Schema + at https://jsonplaceholder.typicode.com/todos/1 +EOF + +diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/ci/fail_bundle_http_non_schema_verbose.sh b/test/ci/fail_bundle_http_non_schema_verbose.sh new file mode 100755 index 00000000..2ef2c1d6 --- /dev/null +++ b/test/ci/fail_bundle_http_non_schema_verbose.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +TMP="$(mktemp -d)" +clean() { rm -rf "$TMP"; } +trap clean EXIT + +cat << 'EOF' > "$TMP/schema.json" +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "allOf": [ { "$ref": "https://jsonplaceholder.typicode.com/todos/1" } ] +} +EOF + +"$1" bundle "$TMP/schema.json" --http --verbose 2> "$TMP/stderr.txt" \ + && CODE="$?" || CODE="$?" +test "$CODE" = "1" || exit 1 + +cat << EOF > "$TMP/expected.txt" +Resolving over HTTP: https://jsonplaceholder.typicode.com/todos/1 +error: The JSON document is not a valid JSON Schema + at https://jsonplaceholder.typicode.com/todos/1 +EOF + +diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/ci/pass_bundle_http.sh b/test/ci/pass_bundle_http.sh new file mode 100755 index 00000000..4deb444f --- /dev/null +++ b/test/ci/pass_bundle_http.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +TMP="$(mktemp -d)" +clean() { rm -rf "$TMP"; } +trap clean EXIT + +cat << 'EOF' > "$TMP/schema.json" +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "allOf": [ { "$ref": "https://json.schemastore.org/mocharc.json" } ] +} +EOF + +"$1" bundle "$TMP/schema.json" --http > "$TMP/result.json" + +cat << 'EOF' > "$TMP/expected.json" +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "allOf": [ { "$ref": "https://json.schemastore.org/mocharc.json" } ] + "$defs": { + "https://json.schemastore.org/mocharc.json": {} + } +} +EOF + +diff "$TMP/result.json" "$TMP/expected.json" diff --git a/test/validate/fail_no_schema.sh b/test/validate/fail_no_schema.sh index 108e7cf9..88b35874 100755 --- a/test/validate/fail_no_schema.sh +++ b/test/validate/fail_no_schema.sh @@ -11,8 +11,8 @@ trap clean EXIT test "$CODE" = "1" || exit 1 cat << 'EOF' > "$TMP/expected.txt" -error: This command expects to pass a path to a schema and a -path to an instance to validate against the schema. For example: +error: This command expects a path to a schema and a path to an +instance to validate against the schema. For example: jsonschema validate path/to/schema.json path/to/instance.json EOF