Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#66667110] Adds command to list instances attached to a load balancer #3

Merged
merged 1 commit into from
Feb 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/elba/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ def list(with_instances = options[:instances])
end


desc "attached BALANCER", "Prints the list of instances attached to a balancer"
option :porcelain, type: :boolean, aliases: :p, desc: "Prints the list in a machine readable format"
def attached(balancer_name = nil, porcelain = options[:porcelain])
unless balancer_name
error "You must specify an ELB"
return
end

elb = find_elb(name: balancer_name)

unless elb
error "Could not find balancer"
return
end

instances = elb.reload.instances

if porcelain
say instances.join(' ')
else
say " * #{elb.id}"
instances.each do |instance_id|
success " - #{instance_id}"
end
end
end


desc "attach INSTANCES", "Attaches given instances ids to a load balancer"
option :to, type: :string, aliases: :t, desc: "Specifies which load balancer to use"
def attach(*instances)
Expand Down
42 changes: 42 additions & 0 deletions spec/lib/elba/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,48 @@
end
end

describe 'attached' do
let(:output) { capture(:stdout) { perform } }
let(:perform) { subject.attached elb.id }

before do
silence(:stdout) { subject.client.attach(instance1.id, elb) }
silence(:stdout) { subject.client.attach(instance2.id, elb) }
end

it 'prints the list of instances attached to an ELB' do
output.should include " * #{elb.id}"
output.should include " - #{instance1.id}"
output.should include " - #{instance2.id}"
end

context 'no balancer name is passed' do
let(:perform) { subject.attached }

it 'exits' do
output.should include 'You must specify an ELB'
end
end

context "the balancer can't be found" do
let(:perform) { subject.attached 'yolo' }

it 'exits' do
output.should include 'Could not find balancer'
end
end

context '--porcelain' do
before do
subject.stub options: { porcelain: true }
end

it 'prints the list of instances attached to an ELB without decoration' do
output.should include "#{instance1.id} #{instance2.id}"
end
end
end

describe 'attach' do
shared_examples_for "asking user" do
before do
Expand Down