Skip to content

Commit

Permalink
Merge pull request #833 from agrare/refactor_regions_spec
Browse files Browse the repository at this point in the history
Refactor regions spec to not hard-code atypical regions
  • Loading branch information
Fryguy authored Nov 13, 2023
2 parents dee8b19 + 8c13c5c commit 8f0f919
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions spec/models/manageiq/providers/amazon/regions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,23 @@
# https://github.com/aws/aws-sdk-ruby/blob/5fe5795e8910bb667996dfc75e4f16b7e69e3980/gems/aws-partitions/partitions.json#L11
ordinary_regions_regexp = /^(us|eu|ap|sa|ca)\-\w+\-\d+$/

# https://docs.aws.amazon.com/general/latest/gr/rande.html - see quotes below
atypical_regions = [
'ap-east-1', # "you must manually enable before you can use..."
'ap-south-2',
'ap-southeast-3',
'ap-southeast-4',
'eu-central-2',
'eu-south-1',
'eu-south-2'
]

current_regions = described_class.regions.reject do |name, _config|
atypical_regions.include?(name) || name !~ ordinary_regions_regexp
name !~ ordinary_regions_regexp
end.map do |_name, config|
{:region_name => config[:name], :endpoint => config[:hostname]}
end

online_regions = VCR.use_cassette(described_class.name.underscore) do
ems.connect.client.describe_regions.to_h[:regions]
ems.connect.client.describe_regions.to_h[:regions].map { |r| r.slice(:region_name, :endpoint) }
end

online_regions.each { |r| r.delete(:opt_in_status) }

# sort for better diff
[current_regions, online_regions].each do |regions|
regions.map! { |r| r.sort.to_h }
regions.sort_by! { |r| r[:region_name] }
end

expect(online_regions).to eq(current_regions)
expect(current_regions).to include(*online_regions)
end

context "disable regions via Settings" do
Expand Down

0 comments on commit 8f0f919

Please sign in to comment.