1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class DiscoveryDocumentTest < ActionDispatch::IntegrationTest
28 test "canonical discovery document is saved to checkout" do
29 get "/discovery/v1/apis/arvados/v1/rest"
30 assert_response :success
31 canonical = Hash[CANONICAL_FIELDS.map { |key| [key, json_response[key]] }]
32 missing = canonical.select { |key| canonical[key].nil? }
33 assert(missing.empty?, "discovery document missing required fields")
35 # (Temporary) sort the hash keys so we can diff JSON below.
36 canonical["resources"] = Hash[canonical["resources"].to_a.sort]
37 canonical["schemas"] = Hash[canonical["schemas"].to_a.sort]
38 actual_json = JSON.pretty_generate(canonical)
40 # Currently the Python SDK is the only component using this copy of the
41 # discovery document, and storing it with the source simplifies the build
42 # process, so it lives there. If another component wants to use it later,
43 # we might consider moving it to a more general subdirectory, but then the
44 # Python build process will need to be extended to accommodate that.
45 src_path = Rails.root.join("../../sdk/python/arvados-v1-discovery.json")
47 expected_json = File.open(src_path) { |f| f.read }
48 # (Temporary) sort the hash keys so we can diff JSON below.
49 j = JSON.parse(expected_json)
50 j["resources"] = Hash[j["resources"].to_a.sort]
51 j["schemas"] = Hash[j["schemas"].to_a.sort]
52 expected_json = JSON.pretty_generate(j)
54 expected_json = "(#{src_path} not found)"
57 out_path = Rails.root.join("tmp", "test-arvados-v1-discovery.json")
58 if expected_json != actual_json
59 File.open(out_path, "w") { |f| f.write(actual_json) }
61 assert_equal(expected_json, actual_json, [
62 "#{src_path} did not match the live discovery document",
63 "Current live version saved to #{out_path}",
64 "Commit that to #{src_path} to regenerate documentation",