Skip to content

Commit 4fafc60

Browse files
committed
Follow meta schema redirects in tests
It looks like they changed these to redirects: ``` % curl 'http://json-schema.org/draft-07/schema#' -I HTTP/1.1 301 Moved Permanently Date: Fri, 13 Oct 2023 21:29:36 GMT Connection: keep-alive Cache-Control: max-age=3600 Expires: Fri, 13 Oct 2023 22:29:36 GMT Location: https://json-schema.org/draft-07/schema Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=4Y8wC8Dh8QkEwNGjF%2FFKlVkfEiFB1hOv3XOnfGJPcIKfna%2FrsYwkURU1zkA5HAgGXRsXFZ3EUCjMOnZiLkXNjDJQ3zvaJJvsS43oAUhIM0uu2CFTfa4QHGRWI%2FpXcULLCqXrAzuUu%2FdG3RU0tFU%3D"}],"group":"cf-nel","max_age":604800} NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800} Vary: Accept-Encoding CF-Cache-Status: DYNAMIC Server: cloudflare CF-RAY: 815aadd5892dcf05-SJC ``` Seems wrong to me, but idk. Added a test helper to resolve redirects when fetching things.
1 parent 5c002fe commit 4fafc60

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

test/json_schema_test_suite_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class JSONSchemaTestSuiteTest < Minitest::Test
4545
path = Pathname.new(__dir__).join('..', 'JSON-Schema-Test-Suite', 'remotes', uri.path.gsub(/\A\//, ''))
4646
JSON.parse(path.read)
4747
else
48-
JSON.parse(Net::HTTP.get(uri))
48+
JSON.parse(fetch(uri))
4949
end
5050
end
5151

test/json_schemer_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def test_published_meta_schemas
422422
JSONSchemer::OpenAPI30::Document::SCHEMA
423423
].each do |meta_schema|
424424
id = meta_schema.key?('$id') ? meta_schema.fetch('$id') : meta_schema.fetch('id')
425-
assert_equal(meta_schema, JSON.parse(Net::HTTP.get(URI(id))))
425+
assert_equal(meta_schema, JSON.parse(fetch(id)))
426426
end
427427
end
428428

test/test_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@
1212
require "json_schemer"
1313

1414
require "minitest/autorun"
15+
16+
def fetch(location, limit = 10)
17+
raise if limit.zero?
18+
uri = URI(location)
19+
response = Net::HTTP.get_response(uri)
20+
case response
21+
when Net::HTTPSuccess
22+
response.body
23+
when Net::HTTPRedirection
24+
fetch(URI.join(uri, response['Location']), limit - 1)
25+
else
26+
response.value.body
27+
end
28+
end

0 commit comments

Comments
 (0)