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")
34 actual_json = JSON.pretty_generate(canonical)
36 # Currently the Python SDK is the only component using this copy of the
37 # discovery document, and storing it with the source simplifies the build
38 # process, so it lives there. If another component wants to use it later,
39 # we might consider moving it to a more general subdirectory, but then the
40 # Python build process will need to be extended to accommodate that.
41 src_path = Rails.root.join("../../sdk/python/arvados-v1-discovery.json")
43 expected_json = File.open(src_path) { |f| f.read }
45 expected_json = "(#{src_path} not found)"
48 out_path = Rails.root.join("tmp", "test-arvados-v1-discovery.json")
49 if expected_json != actual_json
50 File.open(out_path, "w") { |f| f.write(actual_json) }
52 assert_equal(expected_json, actual_json, [
53 "#{src_path} did not match the live discovery document",
54 "Current live version saved to #{out_path}",
55 "Commit that to #{src_path} to regenerate documentation",