Skip to content

Commit

Permalink
Run networking tests as CI-specific tests
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Jun 3, 2024
1 parent 00f0ef3 commit 6f042b2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 10 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"$<TARGET_FILE:jsonschema_cli>")
endif()
endmacro()

add_jsonschema_test_unix(help)
add_jsonschema_test_unix(format_single)
add_jsonschema_test_unix(format_invalid_path)
Expand All @@ -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)
46 changes: 46 additions & 0 deletions test/ci/bundle_remote_http.sh
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",
"$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"

0 comments on commit 6f042b2

Please sign in to comment.