Skip to content

Commit

Permalink
AwsHelpers#ec2_instance_etc_hosts simplified, with enhanced specs
Browse files Browse the repository at this point in the history
  • Loading branch information
dazza-codes committed Sep 22, 2017
1 parent b974bf9 commit a2c7d5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 1 addition & 3 deletions lib/aws/aws_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ def ec2_instance_describe(inst)
# @param public [Boolean] use public or private IP
def ec2_instance_etc_hosts(i, public = true)
ip = public ? i.public_ip_address : i.private_ip_address
public_dns = i.public_dns_name.to_s
private_dns = i.private_dns_name.to_s
"#{ip}\t\t#{public_dns}\t\t#{private_dns}\t\t{HOST}" # template for HOST in settings
"#{ip}\t#{i.public_dns_name}\t#{i.private_dns_name}\t{HOST}" # template for HOST in settings
end

# Content for ~/.ssh/config
Expand Down
13 changes: 10 additions & 3 deletions spec/aws/aws_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,21 @@
it 'works' do
expect(etc_hosts).to be_an String
end
it 'starts with Public IP' do
it 'starts with Public IP (by default)' do
expect(etc_hosts).to start_with inst.public_ip_address
end
it 'starts with Private IP (when requested)' do
etc_hosts = aws_helpers.ec2_instance_etc_hosts(inst, false)
expect(etc_hosts).to start_with inst.private_ip_address
end
it 'includes Public DNS' do
expect(etc_hosts).to include inst.public_dns_name
expect(etc_hosts).to include "\t#{inst.public_dns_name}"
end
it 'includes Private DNS' do
expect(etc_hosts).to include inst.private_dns_name
expect(etc_hosts).to include "\t#{inst.private_dns_name}"
end
it 'includes {HOST} template' do
expect(etc_hosts).to include "\t{HOST}"
end
end

Expand Down

0 comments on commit a2c7d5d

Please sign in to comment.