Skip to content

Commit 3f4f093

Browse files
authored
Add CI HTTP tests for Windows (#731)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 5c6fa6e commit 3f4f093

7 files changed

Lines changed: 576 additions & 0 deletions

test/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ macro(add_jsonschema_test_unix_ci name)
1414
endif()
1515
endmacro()
1616

17+
macro(add_jsonschema_test_windows_ci name)
18+
if(JSONSCHEMA_TESTS_CI AND WIN32)
19+
add_test(NAME JSONSchema.ci.${name} COMMAND
20+
powershell -NoProfile -ExecutionPolicy Bypass -File
21+
"${CMAKE_CURRENT_SOURCE_DIR}/ci/${name}.ps1"
22+
"$<TARGET_FILE:jsonschema_cli>")
23+
endif()
24+
endmacro()
25+
1726
add_jsonschema_test_unix(version_consistency)
1827
add_jsonschema_test_unix(version_command)
1928
add_jsonschema_test_unix(version_option_long)
@@ -829,6 +838,13 @@ add_jsonschema_test_unix_ci(pass_install_http)
829838
add_jsonschema_test_unix_ci(pass_install_add_http)
830839
add_jsonschema_test_unix_ci(precommit_lint)
831840

841+
add_jsonschema_test_windows_ci(pass_bundle_http)
842+
add_jsonschema_test_windows_ci(fail_bundle_http_non_200)
843+
add_jsonschema_test_windows_ci(fail_bundle_http_non_schema)
844+
add_jsonschema_test_windows_ci(fail_validate_http_non_200)
845+
add_jsonschema_test_windows_ci(fail_validate_http_non_schema)
846+
add_jsonschema_test_windows_ci(pass_validate_http)
847+
832848
# TODO: Make this test pass on Linux. It hangs for some reason
833849
if(APPLE)
834850
add_jsonschema_test_unix_ci(pass_validate_json_ref_yaml_http)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
$ErrorActionPreference = "Stop"
2+
$CLI = $args[0]
3+
$TMP = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
4+
New-Item -ItemType Directory -Path $TMP | Out-Null
5+
try {
6+
$schema = Join-Path $TMP "schema.json"
7+
8+
[System.IO.File]::WriteAllText($schema, @'
9+
{
10+
"$schema": "http://json-schema.org/draft-07/schema#",
11+
"title": "Test",
12+
"description": "Test schema",
13+
"allOf": [ { "$ref": "https://one.sourcemeta.com" } ]
14+
}
15+
'@)
16+
17+
$pinfo = [System.Diagnostics.ProcessStartInfo]@{
18+
FileName = $CLI
19+
Arguments = "bundle `"$schema`" --http"
20+
RedirectStandardOutput = $true
21+
RedirectStandardError = $true
22+
UseShellExecute = $false
23+
}
24+
$process = [System.Diagnostics.Process]::Start($pinfo)
25+
$stdout = $process.StandardOutput.ReadToEnd()
26+
$stderr = $process.StandardError.ReadToEnd()
27+
$process.WaitForExit()
28+
29+
if ($process.ExitCode -ne 6) {
30+
throw "Expected exit code 6, got $($process.ExitCode)"
31+
}
32+
33+
$expected = "error: Failed to parse the JSON document`n at line 2`n at column 1`n"
34+
35+
[System.IO.File]::WriteAllText((Join-Path $TMP "stderr.txt"), $stderr)
36+
[System.IO.File]::WriteAllText((Join-Path $TMP "expected.txt"), $expected)
37+
38+
$actualNorm = ($stderr -replace "`r`n", "`n").TrimEnd()
39+
$expectedNorm = ($expected -replace "`r`n", "`n").TrimEnd()
40+
if ($actualNorm -cne $expectedNorm) {
41+
Write-Host "EXPECTED:"
42+
Write-Host $expected
43+
Write-Host "---"
44+
Write-Host "ACTUAL:"
45+
Write-Host $stderr
46+
throw "Stderr output mismatch"
47+
}
48+
} finally {
49+
Remove-Item -Recurse -Force $TMP -ErrorAction SilentlyContinue
50+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
$ErrorActionPreference = "Stop"
2+
$CLI = $args[0]
3+
$TMP = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
4+
New-Item -ItemType Directory -Path $TMP | Out-Null
5+
try {
6+
$schema = Join-Path $TMP "schema.json"
7+
8+
[System.IO.File]::WriteAllText($schema, @'
9+
{
10+
"$schema": "http://json-schema.org/draft-07/schema#",
11+
"title": "Test",
12+
"description": "Test schema",
13+
"allOf": [ { "$ref": "https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema" } ]
14+
}
15+
'@)
16+
17+
$pinfo = [System.Diagnostics.ProcessStartInfo]@{
18+
FileName = $CLI
19+
Arguments = "bundle `"$schema`" --http"
20+
RedirectStandardOutput = $true
21+
RedirectStandardError = $true
22+
UseShellExecute = $false
23+
}
24+
$process = [System.Diagnostics.Process]::Start($pinfo)
25+
$stdout = $process.StandardOutput.ReadToEnd()
26+
$stderr = $process.StandardError.ReadToEnd()
27+
$process.WaitForExit()
28+
29+
if ($process.ExitCode -ne 4) {
30+
throw "Expected exit code 4, got $($process.ExitCode)"
31+
}
32+
33+
$resolvedTmp = (Resolve-Path $TMP).Path.TrimEnd('\')
34+
$expected = @"
35+
error: The JSON document is not a valid JSON Schema
36+
at identifier https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema
37+
at file path $resolvedTmp\schema.json
38+
at location "/allOf/0/`$ref"
39+
"@
40+
41+
[System.IO.File]::WriteAllText((Join-Path $TMP "stderr.txt"), $stderr)
42+
[System.IO.File]::WriteAllText((Join-Path $TMP "expected.txt"), $expected)
43+
44+
$actualNorm = ($stderr -replace "`r`n", "`n").TrimEnd()
45+
$expectedNorm = ($expected -replace "`r`n", "`n").TrimEnd()
46+
if ($actualNorm -cne $expectedNorm) {
47+
Write-Host "EXPECTED:"
48+
Write-Host $expected
49+
Write-Host "---"
50+
Write-Host "ACTUAL:"
51+
Write-Host $stderr
52+
throw "Stderr output mismatch"
53+
}
54+
} finally {
55+
Remove-Item -Recurse -Force $TMP -ErrorAction SilentlyContinue
56+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
$ErrorActionPreference = "Stop"
2+
$CLI = $args[0]
3+
$TMP = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
4+
New-Item -ItemType Directory -Path $TMP | Out-Null
5+
try {
6+
$schema = Join-Path $TMP "schema.json"
7+
$instance = Join-Path $TMP "instance.json"
8+
9+
[System.IO.File]::WriteAllText($schema, @'
10+
{
11+
"$schema": "http://json-schema.org/draft-07/schema#",
12+
"title": "Test",
13+
"description": "Test schema",
14+
"allOf": [ { "$ref": "https://one.sourcemeta.com" } ]
15+
}
16+
'@)
17+
18+
[System.IO.File]::WriteAllText($instance, '{ "type": "string" }')
19+
20+
$pinfo = [System.Diagnostics.ProcessStartInfo]@{
21+
FileName = $CLI
22+
Arguments = "validate `"$schema`" `"$instance`" --http"
23+
RedirectStandardOutput = $true
24+
RedirectStandardError = $true
25+
UseShellExecute = $false
26+
}
27+
$process = [System.Diagnostics.Process]::Start($pinfo)
28+
$stdout = $process.StandardOutput.ReadToEnd()
29+
$stderr = $process.StandardError.ReadToEnd()
30+
$process.WaitForExit()
31+
32+
if ($process.ExitCode -ne 6) {
33+
throw "Expected exit code 6, got $($process.ExitCode)"
34+
}
35+
36+
$expected = "error: Failed to parse the JSON document`n at line 2`n at column 1`n"
37+
38+
[System.IO.File]::WriteAllText((Join-Path $TMP "stderr.txt"), $stderr)
39+
[System.IO.File]::WriteAllText((Join-Path $TMP "expected.txt"), $expected)
40+
41+
$actualNorm = ($stderr -replace "`r`n", "`n").TrimEnd()
42+
$expectedNorm = ($expected -replace "`r`n", "`n").TrimEnd()
43+
if ($actualNorm -cne $expectedNorm) {
44+
Write-Host "EXPECTED:"
45+
Write-Host $expected
46+
Write-Host "---"
47+
Write-Host "ACTUAL:"
48+
Write-Host $stderr
49+
throw "Stderr output mismatch"
50+
}
51+
} finally {
52+
Remove-Item -Recurse -Force $TMP -ErrorAction SilentlyContinue
53+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
$ErrorActionPreference = "Stop"
2+
$CLI = $args[0]
3+
$TMP = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
4+
New-Item -ItemType Directory -Path $TMP | Out-Null
5+
try {
6+
$schema = Join-Path $TMP "schema.json"
7+
$instance = Join-Path $TMP "instance.json"
8+
9+
[System.IO.File]::WriteAllText($schema, @'
10+
{
11+
"$schema": "http://json-schema.org/draft-07/schema#",
12+
"title": "Test",
13+
"description": "Test schema",
14+
"allOf": [ { "$ref": "https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema" } ]
15+
}
16+
'@)
17+
18+
[System.IO.File]::WriteAllText($instance, '{ "type": "string" }')
19+
20+
$pinfo = [System.Diagnostics.ProcessStartInfo]@{
21+
FileName = $CLI
22+
Arguments = "validate `"$schema`" `"$instance`" --http"
23+
RedirectStandardOutput = $true
24+
RedirectStandardError = $true
25+
UseShellExecute = $false
26+
}
27+
$process = [System.Diagnostics.Process]::Start($pinfo)
28+
$stdout = $process.StandardOutput.ReadToEnd()
29+
$stderr = $process.StandardError.ReadToEnd()
30+
$process.WaitForExit()
31+
32+
if ($process.ExitCode -ne 4) {
33+
throw "Expected exit code 4, got $($process.ExitCode)"
34+
}
35+
36+
$resolvedTmp = (Resolve-Path $TMP).Path.TrimEnd('\')
37+
$expected = @"
38+
error: The JSON document is not a valid JSON Schema
39+
at identifier https://schemas.sourcemeta.com/self/v1/api/schemas/stats/jsonschema/2020-12/schema
40+
at file path $resolvedTmp\schema.json
41+
at location "/allOf/0/`$ref"
42+
"@
43+
44+
[System.IO.File]::WriteAllText((Join-Path $TMP "stderr.txt"), $stderr)
45+
[System.IO.File]::WriteAllText((Join-Path $TMP "expected.txt"), $expected)
46+
47+
$actualNorm = ($stderr -replace "`r`n", "`n").TrimEnd()
48+
$expectedNorm = ($expected -replace "`r`n", "`n").TrimEnd()
49+
if ($actualNorm -cne $expectedNorm) {
50+
Write-Host "EXPECTED:"
51+
Write-Host $expected
52+
Write-Host "---"
53+
Write-Host "ACTUAL:"
54+
Write-Host $stderr
55+
throw "Stderr output mismatch"
56+
}
57+
} finally {
58+
Remove-Item -Recurse -Force $TMP -ErrorAction SilentlyContinue
59+
}

0 commit comments

Comments
 (0)