Permalink
Browse files

Sort instances by ID

Change-Id: I30aa621660f8257cd2a9d1901bf760120c408238
  • Loading branch information...
1 parent 6a7f8a4 commit 1ab191c1d1891b4fd4284593014b99607f278f25 Jennifer Hickey and Tim Labeeuw committed Jan 5, 2013
Showing with 74 additions and 2 deletions.
  1. +4 −2 lib/vmc/cli/app/instances.rb
  2. +70 −0 spec/vmc/cli/app/instances_spec.rb
@@ -19,7 +19,7 @@ def instances
line unless quiet?
- spaced(instances) do |i|
+ spaced(instances.sort { |a, b| a.id.to_i <=> b.id.to_i }) do |i|
if quiet?
line i.id
else
@@ -29,9 +29,11 @@ def instances
end
end
+ private
+
def display_instance(i)
start_line "instance #{c("\##{i.id}", :instance)}: "
- puts "#{b(c(i.state.downcase, state_color(i.state)))} "
+ puts "#{b(c(i.state.downcase, state_color(i.state)))}"
indented do
if s = i.since
@@ -0,0 +1,70 @@
+require 'spec_helper'
+require 'stringio'
+
+describe VMC::App::Stats do
+ let(:global) { { :color => false } }
+ let(:inputs) { {:app => apps[0]} }
+ let(:given) { {} }
+ let(:output) { StringIO.new }
+ let(:client) { fake_client(:apps => apps) }
+ let(:apps) { [fake(:app, :name => "basic_app")] }
+ let(:time) { Time.local(2012,11,1,2,30)}
+
+ before do
+ any_instance_of(VMC::CLI) do |cli|
+ stub(cli).client { client }
+ stub(cli).precondition { nil }
+ end
+ stub(client).base.stub!.instances(anything) do
+ {
+ "12" => {:state => "STOPPED", :since => time.to_i, :debug_ip => "foo", :debug_port => "bar", :console_ip => "baz", :console_port => "qux"},
+ "1" => {:state => "STOPPED", :since => time.to_i, :debug_ip => "foo", :debug_port => "bar", :console_ip => "baz", :console_port => "qux"},
+ "2" => {:state => "STARTED", :since => time.to_i, :debug_ip => "foo", :debug_port => "bar", :console_ip => "baz", :console_port => "qux"}
+ }
+ end
+ end
+
+ subject do
+ with_output_to output do
+ Mothership.new.invoke(:instances, inputs, given, global)
+ end
+ end
+
+ describe 'metadata' do
+ let(:command) { Mothership.commands[:instances] }
+
+ describe 'command' do
+ subject { command }
+ its(:description) { should eq "List an app's instances" }
+ it { expect(Mothership::Help.group(:apps, :info)).to include(subject) }
+ end
+
+ include_examples 'inputs must have descriptions'
+
+ describe 'arguments' do
+ subject { command.arguments }
+ it 'has no arguments' do
+ should eq([{:type=>:splat, :value=>nil, :name=>:apps}])
+ end
+ end
+ end
+
+ it 'prints out the instances in the correct order' do
+ subject
+
+ output.rewind
+ expect(output.string).to match /.*instance \#1.*instance \#2.*instance \#12.*/m
+ end
+
+ it 'prints out one of the instances correctly' do
+ subject
+
+ output.rewind
+ expect(output.string).to include <<-OUT.strip_heredoc
+ instance #2: started
+ started: #{time.strftime("%F %r")}
+ debugger: port bar at foo
+ console: port qux at baz
+ OUT
+ end
+end

0 comments on commit 1ab191c

Please sign in to comment.