Skip to content

Commit

Permalink
Merge 2549352 into e7a5331
Browse files Browse the repository at this point in the history
  • Loading branch information
denvazh committed Sep 13, 2017
2 parents e7a5331 + 2549352 commit 96e5420
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: ruby
cache: bundler
rvm:
- 2.2.1
- 2.3.4
script: bundle exec rake test
notifications:
email: false
Expand Down
2 changes: 1 addition & 1 deletion enscalator.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'pry', '~> 0.10.1'
spec.add_development_dependency 'pry-byebug', '~> 3.4.0'
spec.add_development_dependency 'awesome_print', '~> 1.6.1'
spec.add_development_dependency 'looksee', '~> 3.1.0'
spec.add_development_dependency 'looksee', '~> 4.0.0'
spec.add_development_dependency 'yard', '~> 0.8.7.6'
spec.add_development_dependency 'vcr', '~> 2.9.3'
spec.add_development_dependency 'webmock', '~> 1.21.0'
Expand Down
35 changes: 32 additions & 3 deletions lib/enscalator/plugins/route53.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,38 @@ def create_healthcheck(app_name,
Properties: properties
end

# [RESERVED] Create new hosted zone
def create_hosted_zone
fail('method "create_hosted_zone" is not implemented yet')
# Create new public hosted zone
def create_public_hosted_zone(app_name, stack_name, name, comment, tags: [])
properties = {
Name: name
}

properties[:HostedZoneConfig] = {
Comment: comment
} unless comment.blank?

properties[:HostedZoneTags] = [
{
Key: 'Application',
Value: app_name
},
{
Key: 'Stack',
Value: stack_name
}
]
properties[:HostedZoneTags].concat(tags) unless tags.blank?

resource_name = "#{app_name}HostedZone"
resource resource_name,
Type: 'AWS::Route53::HostedZone',
Properties: properties
resource_name
end

# [RESERVED] Create new private hosted zone
def create_private_hosted_zone
fail('method "create_private_hosted_zone" is not implemented')
end

# TODO: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset.html
Expand Down
42 changes: 40 additions & 2 deletions spec/lib/enscalator/plugins/route53_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,45 @@
end
end

describe '#create_hosted_zone' do
describe '#create_public_hosted_zone' do
let(:test_public_hosted_zone) { 'domain.public.zone' }
subject(:cmd_opts) do
default_cmd_opts(template_fixture.name, template_fixture.name.underscore).merge(hosted_zone: test_public_hosted_zone)
end

context 'when invoked with default parameters' do
it 'generates resource template with given fqdn and tags' do
route53_template = template_fixture.new(cmd_opts)
test_comment = 'test comment'
route53_template.create_public_hosted_zone(app_name, cmd_opts[:stack_name], test_public_hosted_zone, test_comment)
dict = route53_template.instance_variable_get(:@dict)
expect(dict[:Description]).to eq(description)
expect(dict[:Resources]["#{app_name}HostedZone"].empty?).to be_falsey
test_resources = dict[:Resources]["#{app_name}HostedZone"]
expect(test_resources[:Type]).to eq('AWS::Route53::HostedZone')
properties = test_resources[:Properties]
expect(properties[:Name]).to eq(test_public_hosted_zone)
expect(properties[:HostedZoneConfig]).to include(**{ Comment: test_comment })
expected_tags = [{ Key: 'Application', Value: app_name }, { Key: 'Stack', Value: cmd_opts[:stack_name], }]
expect(properties[:HostedZoneTags]).to include(*expected_tags)
end
end

context 'when additional tags passed' do
it 'generates resource template using combination of default and provided tags' do
route53_template = template_fixture.new(cmd_opts)
test_comment = 'test comment'
test_tags = [{ Key: 'testtag1', Value: 'sometest1' }]
route53_template.create_public_hosted_zone(app_name, cmd_opts[:stack_name], test_public_hosted_zone, test_comment, tags: test_tags)
dict = route53_template.instance_variable_get(:@dict)
test_resources = dict[:Resources]["#{app_name}HostedZone"]
properties = test_resources[:Properties]
expect(properties[:HostedZoneTags]).to include(*test_tags)
end
end
end

describe '#create_private_hosted_zone' do
let(:test_hosted_zone) { 'private.enjapan.test' }
subject(:cmd_opts) do
default_cmd_opts(template_fixture.name, template_fixture.name.underscore).merge(hosted_zone: test_hosted_zone)
Expand All @@ -84,7 +122,7 @@
context 'when not implemented method gets invoked' do
it 'raises Runtime exception' do
route53_template = template_fixture.new(cmd_opts)
expect { route53_template.create_hosted_zone }.to raise_exception(RuntimeError)
expect { route53_template.create_private_hosted_zone }.to raise_exception(RuntimeError)
end
end
end
Expand Down

0 comments on commit 96e5420

Please sign in to comment.