Sha256: d577ebdc36de0a3f8503fe99217dbb8c452e6e469605b90577da85d3fef9e210

Contents?: true

Size: 1.42 KB

Versions: 5

Compression:

Stored size: 1.42 KB

Contents

require 'test_plugin_helper'

module ForemanSalt
  class GrainsImporterTest < ActiveSupport::TestCase
    setup do
      User.current = User.find_by_login "admin"
      Setting[:create_new_host_when_facts_are_uploaded] = true

      # I don't even know, the plug-in successfully registers the importer
      # in development, and even on the Rails test console but not here
      # in the test itself...
      ::FactImporter.stubs(:importer_for).returns(ForemanSalt::FactImporter)

      grains = JSON.parse(File.read(File.join(Engine.root, "test", "unit", "grains_centos.json")))
      @host  = grains["name"]
      @facts = grains["facts"]
    end

    test "importing salt grains creates a host" do
      refute Host.find_by_name(@host)
      ::Host::Managed.import_host_and_facts @host, @facts
      assert Host.find_by_name(@host)
    end

    test "grains are successfully imported for a host" do
      (host, state) = ::Host::Managed.import_host_and_facts @host, @facts
      assert_equal 'CentOS', host.facts_hash['operatingsystem']
    end

    test "nested facts have valid parents" do
      (host, state) = ::Host::Managed.import_host_and_facts @host, @facts
      parent = ::FactName.find_by_name('cpu_flags')
      children = host.fact_values.with_fact_parent_id(parent)
      assert_not_empty children
      assert_empty children.map(&:fact_name).reject { |fact| fact.name =~ /\Acpu_flags#{FactName::SEPARATOR}[0-9]+/ }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_salt-1.1.0 test/unit/grains_importer_test.rb
foreman_salt-1.0.0 test/unit/grains_importer_test.rb
foreman_salt-0.0.4 test/unit/grains_importer_test.rb
foreman_salt-0.0.3 test/unit/grains_importer_test.rb
foreman_salt-0.0.2 test/unit/grains_importer_test.rb