File tree Expand file tree Collapse file tree 2 files changed +44
-4
lines changed
cookbooks/aws-parallelcluster-shared Expand file tree Collapse file tree 2 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -2,17 +2,22 @@ def aws_region
2
2
node [ 'cluster' ] [ 'region' ]
3
3
end
4
4
5
+ CLASSIC_AWS_DOMAIN = "amazonaws.com" . freeze
6
+ CHINA_AWS_DOMAIN = "amazonaws.com.cn" . freeze
7
+ US_ISO_AWS_DOMAIN = "c2s.ic.gov" . freeze
8
+ US_ISOB_AWS_DOMAIN = "sc2s.sgov.gov" . freeze
9
+
5
10
def aws_domain
6
11
# Get the aws domain name
7
12
region = aws_region
8
13
if region . start_with? ( "cn-" )
9
- "amazonaws.com.cn"
14
+ CHINA_AWS_DOMAIN
10
15
elsif region . start_with? ( "us-iso-" )
11
- "c2s.ic.gov"
16
+ US_ISO_AWS_DOMAIN
12
17
elsif region . start_with? ( "us-isob-" )
13
- "sc2s.sgov.gov"
18
+ US_ISOB_AWS_DOMAIN
14
19
else
15
- "amazonaws.com"
20
+ CLASSIC_AWS_DOMAIN
16
21
end
17
22
end
18
23
Original file line number Diff line number Diff line change
1
+ require_relative '../../../libraries/environment'
2
+ require 'spec_helper'
3
+
4
+ describe 'aws_domain' do
5
+ shared_examples 'a valid aws_domain function' do |region , expected_aws_domain |
6
+ it 'returns the correct AWS domain' do
7
+ allow_any_instance_of ( Object ) . to receive ( :aws_region ) . and_return ( region )
8
+ # We must force aws_domain to call the original function because
9
+ # the spec_helper configures aws_domain to return a mocked value for all rspec tests.
10
+ allow_any_instance_of ( Object ) . to receive ( :aws_domain ) . and_call_original
11
+
12
+ expect ( aws_domain ) . to eq ( expected_aws_domain )
13
+ end
14
+ end
15
+
16
+ context 'when in CN region' do
17
+ include_examples 'a valid aws_domain function' , 'cn-WHATEVER' , 'amazonaws.com.cn'
18
+ end
19
+
20
+ context 'when in US-ISO region' do
21
+ include_examples 'a valid aws_domain function' , 'us-iso-WHATEVER' , 'c2s.ic.gov'
22
+ end
23
+
24
+ context 'when in US-ISOB region' do
25
+ include_examples 'a valid aws_domain function' , 'us-isob-' , 'sc2s.sgov.gov'
26
+ end
27
+
28
+ context 'when in GovCloud region' do
29
+ include_examples 'a valid aws_domain function' , 'us-gov-WHATEVER' , 'amazonaws.com'
30
+ end
31
+
32
+ context 'when in whatever else region' do
33
+ include_examples 'a valid aws_domain function' , 'WHATEVER-ELSE' , 'amazonaws.com'
34
+ end
35
+ end
You can’t perform that action at this time.
0 commit comments