Sha256: 653ad8873b609bad12042019e49c924a5264b7981815f9fad3aaf9f74305adc6

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

require 'test_helper'

class HostDiscoveredTest < ActiveSupport::TestCase
  setup do
    User.current = User.find_by_login "admin"
    FactoryGirl.create(:setting,
                       name: 'discovery_fact',
                       value: 'macaddress',
                       category: 'Setting::Discovered')
  end

  test "should be able to create Host::Discovered objects" do
    host = Host.create :name => "mydiscoveredhost", :type => "Host::Discovered"
    assert host.is_a?(Host::Discovered)
  end

  test "should import facts from yaml as Host::Discovered" do
    raw = parse_json_fixture('/facts.json')
    assert Host::Discovered.importHostAndFacts(raw['facts'])
  end

  test "should raise when fact_name setting isn't present" do
    raw = parse_json_fixture('/facts.json')
    Setting[:discovery_fact] = 'macaddress_foo'
    assert_raises Foreman::Exception do
      Host::Discovered.importHostAndFacts(raw['facts'])
    end
  end

  test "should be able to refresh facts" do
    host = Host.create :name => "mydiscoveredhost", :ip => "1.2.3.4", :type => "Host::Discovered"
    raw = parse_json_fixture('/facts.json')
    ForemanDiscovery::Facts.any_instance.stubs(:facts).returns(raw['facts'])
    assert host.refresh_facts
  end

  def parse_json_fixture(relative_path)
    return JSON.parse(File.read(File.expand_path(File.dirname(__FILE__) + relative_path)))
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.3.0.rc2 test/unit/host_discovered_test.rb
foreman_discovery-1.3.0.rc1 test/unit/host_discovered_test.rb
foreman_discovery-1.2.0 test/unit/host_discovered_test.rb
foreman_discovery-1.2.0.rc2 test/unit/host_discovered_test.rb
foreman_discovery-1.2.0.rc1 test/unit/host_discovered_test.rb