Sha256: 766c82c317225f92bd05ffaafe9ac3e226528f0fd1f9407fb479df28baa19101

Contents?: true

Size: 1.48 KB

Versions: 104

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require 'test_plugin_helper'
# Unit tests for AnsibleReportImporter
# This class is just meant to capture the config reports coming
# from Ansible and change anything that is required
class AnsibleReportImporterTest < ActiveSupport::TestCase
  setup do
    @raw = { 'host' => '192.168.121.1' }
    @importer = ::ConfigReportImporter.new(@raw)
  end

  test 'finds host when the hostname is given as the IP' do
    host = ::FactoryBot.create(:host, :ip => @raw['host'])
    ForemanAnsible::AnsibleReportScanner.expects(:ansible_report?).returns(true)
    assert_equal @importer.host, host
  end

  test 'creates new host if IP is not found' do
    ForemanAnsible::AnsibleReportScanner.expects(:ansible_report?).returns(true)
    assert @importer.host.new_record?
  end

  test 'finds host when given partially qualified name' do
    host = ::FactoryBot.create(:host, :hostname => 'ansible-host.example.com')
    ForemanAnsible::AnsibleReportScanner.expects(:ansible_report?).returns(true)
    assert_equal host, ::ConfigReportImporter.new({ 'host' => 'ansible-host' }).host
  end

  test 'creates a new host when multiple hosts for partially qualified name are found' do
    ::FactoryBot.create(:host, :hostname => 'ansible-host.example.com')
    ::FactoryBot.create(:host, :hostname => 'ansible-host.dummy.org')
    ForemanAnsible::AnsibleReportScanner.expects(:ansible_report?).returns(true)
    assert ::ConfigReportImporter.new({ 'host' => 'ansible-host' }).host.new_record?
  end
end

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
foreman_ansible-6.3.2 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-6.3.1 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-6.4.1 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-6.4.0 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-6.3.0 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-6.2.0 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-6.1.1 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-6.0.2 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-6.1.0 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-6.0.1 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-5.1.3 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-6.0.0 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-5.1.2 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-5.1.1 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-5.1.0 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-4.0.3.5 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-4.0.3.4 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-4.0.3.3 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-4.0.3.2 test/unit/services/ansible_report_importer_test.rb
foreman_ansible-5.0.1 test/unit/services/ansible_report_importer_test.rb