From 3caae8900ff14d109f992e0fdb571ba438842aa6 Mon Sep 17 00:00:00 2001 From: Juli Tera Date: Tue, 19 Nov 2024 08:13:09 -0800 Subject: [PATCH] Update more specs from JSON.load to load_file --- gems/aws-eventstream/spec/spec_helper.rb | 2 +- .../spec/aws_partitions_spec.rb | 37 ++++++++++--------- gems/aws-sdk-core/spec/api_helper.rb | 23 ++++++------ .../spec/aws/xml/error_handler_spec.rb | 12 ++++-- gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb | 4 +- tasks/update-defaults-mode.rake | 2 +- 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/gems/aws-eventstream/spec/spec_helper.rb b/gems/aws-eventstream/spec/spec_helper.rb index 702a7c7a7c3..47f2110fbaf 100644 --- a/gems/aws-eventstream/spec/spec_helper.rb +++ b/gems/aws-eventstream/spec/spec_helper.rb @@ -28,7 +28,7 @@ def expected_decoded_error(path) end def convert_msg(path) - hash = JSON.load(File.read(path)) + hash = JSON.load_file(path) Aws::EventStream::Message.new( headers: build_headers(hash['headers']), payload: StringIO.new(Base64.decode64(hash['payload'])) diff --git a/gems/aws-partitions/spec/aws_partitions_spec.rb b/gems/aws-partitions/spec/aws_partitions_spec.rb index 17ac395df3f..027d42d6323 100644 --- a/gems/aws-partitions/spec/aws_partitions_spec.rb +++ b/gems/aws-partitions/spec/aws_partitions_spec.rb @@ -242,8 +242,9 @@ module Aws describe 'metadata' do let(:partition_metadata_json) do - path = File.expand_path('../test_partitions_metadata.json', __FILE__) - JSON.load(File.read(path)) + JSON.load_file( + File.expand_path('test_partitions_metadata.json', __dir__) + ) end before do @@ -267,13 +268,12 @@ module Aws end after do - path = File.expand_path('../../partitions.json', __FILE__) - original_json = JSON.load(File.read(path)) + original_json = + JSON.load_file(File.expand_path('../partitions.json', __dir__)) Partitions.clear Partitions.add(original_json) Partitions.merge_metadata( - JSON.load(File.read( - File.expand_path('../../partitions-metadata.json', __FILE__))) + JSON.load_file(File.expand_path('../partitions-metadata.json', __dir__)) ) end end @@ -281,8 +281,10 @@ module Aws # normal endpoint testing describe Partitions::EndpointProvider do let(:partition_json) do - path = File.expand_path('../test_partition.json', __FILE__) - JSON.load(File.read(path)) + JSON.load_file( + File.expand_path('test_partition.json', __dir__) + ) + end before { Partitions.add(partition_json) } @@ -428,8 +430,9 @@ module Aws # variants endpoints testing describe Partitions::EndpointProvider do let(:fips_partition_json) do - path = File.expand_path('../variant_test_partition.json', __FILE__) - JSON.load(File.read(path)) + JSON.load_file( + File.expand_path('variant_test_partition.json', __dir__) + ) end before do @@ -438,18 +441,19 @@ module Aws end after do - path = File.expand_path('../../partitions.json', __FILE__) - original_json = JSON.load(File.read(path)) + original_json = + JSON.load_file(File.expand_path('../partitions.json', __dir__)) Partitions.clear Partitions.add(original_json) Partitions.merge_metadata( - JSON.load(File.read( - File.expand_path('../../partitions-metadata.json', __FILE__))) + JSON.load_file( + File.expand_path('../partitions-metadata.json', __dir__) + ) ) end - path = File.expand_path('../variant_test_cases.json', __FILE__) - test_cases = JSON.load(File.read(path)) + test_cases = + JSON.load_file(File.expand_path('variant_test_cases.json', __dir__)) describe '.resolve' do test_cases.each_with_index do |test_case, index| @@ -503,6 +507,5 @@ module Aws end end end - end end diff --git a/gems/aws-sdk-core/spec/api_helper.rb b/gems/aws-sdk-core/spec/api_helper.rb index 61bc53601fd..ddf345eb357 100644 --- a/gems/aws-sdk-core/spec/api_helper.rb +++ b/gems/aws-sdk-core/spec/api_helper.rb @@ -7,48 +7,47 @@ class << self def sample_json # dynamodb @sample_json ||= begin - api = File.expand_path('../fixtures/apis/dynamodb.json', __FILE__) - api = JSON.load(File.read(api)) + api = + JSON.load_file(File.expand_path('fixtures/apis/dynamodb.json', __dir__)) sample_service(api: api) end end def sample_query # iam @sample_query ||= begin - api = File.expand_path('../fixtures/apis/iam.json', __FILE__) - api = JSON.load(File.read(api)) + api = + JSON.load_file(File.expand_path('fixtures/apis/iam.json', __dir__)) sample_service(api: api) end end def sample_rest_xml # s3 @sample_rest_xml ||= begin - api = File.expand_path('../fixtures/apis/s3.json', __FILE__) - api = JSON.load(File.read(api)) + api = + JSON.load_file(File.expand_path('fixtures/apis/s3.json', __dir__)) sample_service(api: api) end end def sample_rest_json # glacier @sample_rest_json ||= begin - api = File.expand_path('../fixtures/apis/glacier.json', __FILE__) - api = JSON.load(File.read(api)) + api = + JSON.load_file(File.expand_path('fixtures/apis/glacier.json', __dir__)) sample_service(api: api) end end def sample_ec2 # ec2 has its own protocol @sample_ec2 ||= begin - api = File.expand_path('../fixtures/apis/ec2.json', __FILE__) - api = JSON.load(File.read(api)) + api = JSON.load_file(File.expand_path('fixtures/apis/ec2.json', __dir__)) sample_service(api: api) end end def sample_rpcv2_cbor # cloudwatch logs changed to cbor @sample_rpcv2_cbor ||= begin - api = File.expand_path('../fixtures/apis/logs.json', __FILE__) - api = JSON.load(File.read(api)) + api = + JSON.load_file(File.expand_path('fixtures/apis/logs.json', __dir__)) sample_service(api: api) end end diff --git a/gems/aws-sdk-core/spec/aws/xml/error_handler_spec.rb b/gems/aws-sdk-core/spec/aws/xml/error_handler_spec.rb index af4e5320c0a..f0cd945301d 100644 --- a/gems/aws-sdk-core/spec/aws/xml/error_handler_spec.rb +++ b/gems/aws-sdk-core/spec/aws/xml/error_handler_spec.rb @@ -8,7 +8,9 @@ module Xml let(:cloudfront) { ApiHelper.sample_service( - api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/cloudfront.json', __FILE__))) + api: JSON.load_file( + File.expand_path('../../fixtures/apis/cloudfront.json', __dir__) + ) )::Client.new( region: 'us-west-2', retry_limit: 0, @@ -19,7 +21,9 @@ module Xml let(:route53) { ApiHelper.sample_service( - api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/route53.json', __FILE__))) + api: JSON.load_file( + File.expand_path('../../fixtures/apis/route53.json', __dir__) + ) )::Client.new( region: 'us-west-2', retry_limit: 0, @@ -39,7 +43,9 @@ module Xml let(:sns) { ApiHelper.sample_service( - api: JSON.load(File.read(File.expand_path('../../../fixtures/apis/sns.json', __FILE__))) + api: JSON.load_file( + File.expand_path('../../fixtures/apis/sns.json', __dir__) + ) )::Client.new( region: 'us-west-2', retry_limit: 0, diff --git a/gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb b/gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb index 0e8da29d3c7..10b24230189 100644 --- a/gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb +++ b/gems/aws-sdk-s3/spec/encryptionV2/kat_spec.rb @@ -27,8 +27,8 @@ def self.build_kat(raw_kat) ) end - fixture_path = File.expand_path('../../fixtures/encryption', __FILE__) - kats = JSON.load File.new(File.join(fixture_path, 'aes_gcm_kat.json')) + fixture_path = File.expand_path('../fixtures/encryption', __dir__) + kats = JSON.load_file(File.new(File.join(fixture_path, 'aes_gcm_kat.json'))) kats.each_with_index do |raw, i| kat = build_kat(raw) diff --git a/tasks/update-defaults-mode.rake b/tasks/update-defaults-mode.rake index 7e4fb9e3897..8892f113c26 100644 --- a/tasks/update-defaults-mode.rake +++ b/tasks/update-defaults-mode.rake @@ -10,7 +10,7 @@ task 'update-defaults-mode', [:defaults_file] do |t, args| end puts "Loading defaults from: #{defaults_file}" - defaults = JSON.load(File.read(defaults_file)) + defaults = JSON.load_file(defaults_file) default_mode_docs = ["

The following :default_mode values are supported:

"] default_mode_docs << "