Sha256: ec0b057dfda8dacee49a9c272056b00cd05ec3392606ebc766d9f8e699ea8abc

Contents?: true

Size: 1.83 KB

Versions: 5

Compression:

Stored size: 1.83 KB

Contents

require File.expand_path '../../spec_helper.rb', __FILE__
require File.expand_path '../../../lib/helpers/puppetdb.rb', __FILE__

describe Helpers::PuppetDB, '#get_nodes' do

  it 'should return json when puppetdb details are valid' do

    stub_request(:get, 'http://localhost:8080/v3/nodes').
        with(:headers => {'Accept'=>['*/*', 'application/json'], 'User-Agent'=>'Ruby'}).
        to_return(:status => 200, :body => '{ "name" : "test.internal" }', :headers => {})

    puppetdb = Helpers::PuppetDB.new('localhost', '8080')
    nodes = puppetdb.get_nodes
    nodes.should_not be_empty
  end

  it 'should return an empty collection when the details are invalid' do

    stub_request(:get, 'http://fubar:8080/v3/nodes').
        with(:headers => {'Accept'=>['*/*', 'application/json'], 'User-Agent'=>'Ruby'}).
        to_return(:status => 404, :body => '', :headers => {})

    puppetdb = Helpers::PuppetDB.new('fubar', '8080')
    nodes = puppetdb.get_nodes
    nodes.should be_empty
  end

end

describe Helpers::PuppetDB, '#get_facts' do

  it 'should return json when puppetdb details are valid' do

    stub_request(:get, 'http://localhost:8080/v3/facts').
        with(:headers => {'Accept'=>['*/*', 'application/json'], 'User-Agent'=>'Ruby'}).
        to_return(:status => 200, :body => '{ "name" : "osfamily" }', :headers => {})

    puppetdb = Helpers::PuppetDB.new('localhost', '8080')
    nodes = puppetdb.get_facts
    nodes.should_not be_empty
  end

  it 'should return an empty collection when the details are invalid' do

    stub_request(:get, 'http://fubar:8080/v3/facts').
        with(:headers => {'Accept'=>['*/*', 'application/json'], 'User-Agent'=>'Ruby'}).
        to_return(:status => 404, :body => '', :headers => {})

    puppetdb = Helpers::PuppetDB.new('fubar', '8080')
    nodes = puppetdb.get_facts
    nodes.should be_empty
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
puppetdb_rundeck-1.0.0 spec/helpers/puppetdb_spec.rb
puppetdb_rundeck-0.3.1 spec/helpers/puppetdb_spec.rb
puppetdb_rundeck-0.3.0 spec/helpers/puppetdb_spec.rb
puppetdb_rundeck-0.2.3 spec/helpers/puppetdb_spec.rb
puppetdb_rundeck-0.2.2 spec/helpers/puppetdb_spec.rb