Sha256: a18cda8765719efe2d7a5e45b5edd6c38ba47c9a2310d7e57548a84e3f24baba

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 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.import_host_and_facts(raw['facts'])
    assert Host::Discovered.find_by_name('mace41f13cc3658')
  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.import_host_and_facts(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

6 entries across 6 versions & 1 rubygems

Version Path
foreman_discovery-1.4.0.rc4 test/unit/host_discovered_test.rb
foreman_discovery-1.4.0.rc3 test/unit/host_discovered_test.rb
foreman_discovery-1.4.0.rc2 test/unit/host_discovered_test.rb
foreman_discovery-1.4.0.rc1 test/unit/host_discovered_test.rb
foreman_discovery-1.3.0 test/unit/host_discovered_test.rb
foreman_discovery-1.3.0.rc3 test/unit/host_discovered_test.rb