Project

General

Profile

Revision dcfb98fd

Added by Thomas McKay almost 9 years ago

hosts-test - confirm expected host is present

View differences:

test/csv_test_helper.rb
20 20

  
21 21
def ctx
22 22
  {
23
    :adapter => :csv,
24 23
    :interactive => false
25 24
  }
26 25
end
27 26

  
28
def hammer
29
  HammerCLI::MainCommand.new("", ctx)
27
def hammer(context=nil)
28
  HammerCLI::MainCommand.new("", context || ctx)
30 29
end
31 30

  
32 31
def capture
test/hosts_test.rb
1
require File.join(File.dirname(__FILE__), 'csv_test_helper')
2

  
3
describe 'setup' do
4

  
5
  extend CommandTestHelper
6

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

  
11
  context 'Test hosts from setup' do
12

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

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

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

  
31
    it "hammer -v host info --id $id" do
32
      stdout,stderr = capture {
33
        hammer.run(%W{-v host info --id #{host_id}})
34
      }
35
      stderr.must_equal ''
36
      attributes = {}
37
      stdout.split("\n").each do |line|
38
        name,value = line.split(":")
39
        attributes[name.strip] = (value.nil? ? '' : value.strip)
40
      end
41
      attributes['Id'].must_equal host_id
42
      attributes['Name'].must_equal 'dhcp129-000.megacorp.com'
43

  
44
    end
45
  end
46

  
47
end

Also available in: Unified diff