From 080694730b420421dd46f67bc31590541b7f2efa Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 3 Jun 2024 12:33:17 -0300 Subject: [PATCH] Run networking tests as CI-specific tests (#29) Signed-off-by: Juan Cruz Viotti --- .github/workflows/package.yml | 1 + .github/workflows/test.yml | 1 + CMakeLists.txt | 1 + Makefile | 1 + test/CMakeLists.txt | 12 +++++++-- test/ci/bundle_remote_http.sh | 46 +++++++++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 2 deletions(-) create mode 100755 test/ci/bundle_remote_http.sh diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 826e6559..370a5416 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -39,6 +39,7 @@ jobs: cmake -S . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -DJSONSCHEMA_TESTS:BOOL=ON + -DJSONSCHEMA_TESTS_CI:BOOL=ON -DJSONSCHEMA_CONTINUOUS:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_COMPILE_WARNING_AS_ERROR:BOOL=ON diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 37e8f120..eafbb2ef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,6 +37,7 @@ jobs: cmake -S . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release -DJSONSCHEMA_TESTS:BOOL=ON + -DJSONSCHEMA_TESTS_CI:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_COMPILE_WARNING_AS_ERROR:BOOL=ON - run: cmake --build ./build --config Release --target clang_format_test diff --git a/CMakeLists.txt b/CMakeLists.txt index 20ed664f..1e8b0f17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ include(cmake/CompilerOptions.cmake) # Options option(JSONSCHEMA_TESTS "Build the JSON Schema CLI tests" OFF) +option(JSONSCHEMA_TESTS_CI "Build the JSON Schema CLI CI tests" OFF) option(JSONSCHEMA_CONTINUOUS "Perform a continuous JSON Schema CLI release" ON) find_package(JSONToolkit REQUIRED) diff --git a/Makefile b/Makefile index 36495fec..e624e7de 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ configure: .always -DCMAKE_BUILD_TYPE:STRING=$(PRESET) \ -DCMAKE_COMPILE_WARNING_AS_ERROR:BOOL=ON \ -DJSONSCHEMA_TESTS:BOOL=ON \ + -DJSONSCHEMA_TESTS_CI:BOOL=OFF \ -DJSONSCHEMA_CONTINUOUS:BOOL=ON \ -DBUILD_SHARED_LIBS:BOOL=$(SHARED) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e30acfe2..26b7f914 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,6 +6,14 @@ macro(add_jsonschema_test_unix name) endif() endmacro() +macro(add_jsonschema_test_unix_ci name) + if(JSONSCHEMA_TESTS_CI AND UNIX) + add_test(NAME JSONSchema.ci.${name} COMMAND + "${CMAKE_CURRENT_SOURCE_DIR}/ci/${name}.sh" + "$") + endif() +endmacro() + add_jsonschema_test_unix(help) add_jsonschema_test_unix(format_single) add_jsonschema_test_unix(format_invalid_path) @@ -31,5 +39,5 @@ add_jsonschema_test_unix(lint_pass) add_jsonschema_test_unix(lint_fail) add_jsonschema_test_unix(lint_fix) -# TODO: Enable certain tests (if a given CMake option -# is set) that perform outbound HTTP requests +# CI specific tests +add_jsonschema_test_unix_ci(bundle_remote_http) diff --git a/test/ci/bundle_remote_http.sh b/test/ci/bundle_remote_http.sh new file mode 100755 index 00000000..c92534f2 --- /dev/null +++ b/test/ci/bundle_remote_http.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", + "$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"