From 6f042b2a67de1f3d5b00e6a02f59645e59c9b7d2 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 3 Jun 2024 11:30:20 -0400 Subject: [PATCH] Run networking tests as CI-specific tests 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 826e655..370a541 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 37e8f12..eafbb2e 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 20ed664..1e8b0f1 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 36495fe..e624e7d 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 e30acfe..26b7f91 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 0000000..c92534f --- /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"