Skip to content

Commit

Permalink
Merge pull request Katello#25 from thomasmckay/hosts-test
Browse files Browse the repository at this point in the history
hosts-test - confirm expected host is present
  • Loading branch information
Tom McKay committed Mar 8, 2014
2 parents 2936f6a + dcfb98f commit 6130dbe
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
5 changes: 2 additions & 3 deletions test/csv_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@

def ctx
{
:adapter => :csv,
:interactive => false
}
end

def hammer
HammerCLI::MainCommand.new("", ctx)
def hammer(context=nil)
HammerCLI::MainCommand.new("", context || ctx)
end

def capture
Expand Down
47 changes: 47 additions & 0 deletions test/hosts_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require File.join(File.dirname(__FILE__), 'csv_test_helper')

describe 'setup' do

extend CommandTestHelper

before :each do
HammerCLI::Settings.load_from_file ['test/config.yml']
end

context 'Test hosts from setup' do

it "hammer -v --csv host list --search=name=dhcp129-000.megacorp.com" do
stdout,stderr = capture {
hammer.run(%W{-v --csv host list --search=name=dhcp129-000.megacorp.com})
}
stderr.must_equal ''
stdout.split("\n").length.must_equal 2
stdout.must_match /.*dhcp129-000\.megacorp\.com.*/

host_id = stdout.split("\n")[1].split(",")[0]
end

let(:host_id) {
stdout,stderr = capture {
hammer.run(%W{-v --csv host list --search=name=dhcp129-000.megacorp.com})
}
host_id = stdout.split("\n")[1].split(",")[0]
}

it "hammer -v host info --id $id" do
stdout,stderr = capture {
hammer.run(%W{-v host info --id #{host_id}})
}
stderr.must_equal ''
attributes = {}
stdout.split("\n").each do |line|
name,value = line.split(":")
attributes[name.strip] = (value.nil? ? '' : value.strip)
end
attributes['Id'].must_equal host_id
attributes['Name'].must_equal 'dhcp129-000.megacorp.com'

end
end

end

0 comments on commit 6130dbe

Please sign in to comment.