20978: Merge branch 'main' into 20978-instance-types
[arvados.git] / services / api / test / integration / discovery_document_test.rb
index b592d6163916c5580ffa8fbebe4517bf330bc60b..37e775029733be80bcf101f8f544da626c985372 100644 (file)
@@ -31,8 +31,8 @@ class DiscoveryDocumentTest < ActionDispatch::IntegrationTest
     canonical = Hash[CANONICAL_FIELDS.map { |key| [key, json_response[key]] }]
     missing = canonical.select { |key| canonical[key].nil? }
     assert(missing.empty?, "discovery document missing required fields")
+    actual_json = JSON.pretty_generate(canonical)
 
-    expected = JSON.pretty_generate(canonical)
     # Currently the Python SDK is the only component using this copy of the
     # discovery document, and storing it with the source simplifies the build
     # process, so it lives there. If another component wants to use it later,
@@ -40,16 +40,16 @@ class DiscoveryDocumentTest < ActionDispatch::IntegrationTest
     # Python build process will need to be extended to accommodate that.
     src_path = Rails.root.join("../../sdk/python/arvados-v1-discovery.json")
     begin
-      actual = File.open(src_path) { |f| f.read }
+      expected_json = File.open(src_path) { |f| f.read }
     rescue Errno::ENOENT
-      actual = "(#{src_path} not found)"
+      expected_json = "(#{src_path} not found)"
     end
 
     out_path = Rails.root.join("tmp", "test-arvados-v1-discovery.json")
-    if expected != actual
-      File.open(out_path, "w") { |f| f.write(expected) }
+    if expected_json != actual_json
+      File.open(out_path, "w") { |f| f.write(actual_json) }
     end
-    assert_equal(expected, actual, [
+    assert_equal(expected_json, actual_json, [
                    "#{src_path} did not match the live discovery document",
                    "Current live version saved to #{out_path}",
                    "Commit that to #{src_path} to regenerate documentation",