Sha256: fc7d71ba00122ee88d5f2be5441b99784f93063df5ecd23b1efa19792e1fcc04

Contents?: true

Size: 1.72 KB

Versions: 18

Compression:

Stored size: 1.72 KB

Contents

require 'test_plugin_helper'

class ArchivedReportGeneratorTest < ActiveSupport::TestCase
  setup do
    User.current = User.find_by(login: 'secret_admin')

    env = FactoryBot.create(:katello_k_t_environment)
    cv = env.content_views << FactoryBot.create(:katello_content_view, organization: env.organization)

    @host = FactoryBot.create(
      :host,
      :with_subscription,
      :with_content,
      content_view: cv.first,
      lifecycle_environment: env,
      organization: env.organization
    )

    @host.subscription_facet.pools << FactoryBot.create(:katello_pool, account_number: '1234', cp_id: 1)
  end

  def interesting_facts
    [
      'dmi::system::uuid',
      'virt::uuid',
      'cpu::cpu(s)',
      'cpu::cpu_socket(s)',
      'cpu::core(s)_per_socket',
      'memory::memtotal',
      'dmi::bios::vendor',
      'dmi::bios::version',
      'dmi::bios::relase_date',
      'distribution::name',
      'uname::release',
      'lscpu::flags',
    ]
  end

  def fact_names
    @fact_names ||= Hash[
      interesting_facts.map do |fact|
        [fact, FactoryBot.create(:fact_name, name: fact, type: 'Katello::RhsmFactName')]
      end
    ]
  end

  test 'generates a report for a single host' do
    batches = Host.where(id: @host.id).in_batches
    test_org = FactoryBot.create(:organization)

    ForemanInventoryUpload::Generators::Queries.expects(:for_org).with(test_org.id).returns(batches)
    Dir.mktmpdir do |tmpdir|
      target = File.join(tmpdir, 'test.tar.gz')
      generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
      generator.render(organization: test_org.id)

      files = Dir["#{tmpdir}/*"]
      assert_equal "#{tmpdir}/test.tar.gz", files.first
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
foreman_rh_cloud-0.9.5 test/unit/archived_report_generator_test.rb
foreman_rh_cloud-1.0.5 test/unit/archived_report_generator_test.rb
foreman_rh_cloud-2.0.5 test/unit/archived_report_generator_test.rb
foreman_rh_cloud-0.9.4.1 test/unit/archived_report_generator_test.rb
foreman_rh_cloud-1.0.4.1 test/unit/archived_report_generator_test.rb
foreman_rh_cloud-1.0.4 test/unit/archived_report_generator_test.rb
foreman_rh_cloud-2.0.4 test/unit/archived_report_generator_test.rb
foreman_rh_cloud-0.9.4 test/unit/archived_report_generator_test.rb
foreman_inventory_upload-2.0.4.pre.2 test/unit/archived_report_generator_test.rb
foreman_inventory_upload-2.0.4.pre.1 test/unit/archived_report_generator_test.rb
foreman_inventory_upload-2.0.3 test/unit/archived_report_generator_test.rb
foreman_inventory_upload-1.0.3 test/unit/archived_report_generator_test.rb
foreman_inventory_upload-0.9.2 test/unit/archived_report_generator_test.rb
foreman_inventory_upload-1.0.2 test/unit/archived_report_generator_test.rb
foreman_inventory_upload-0.9.1 test/unit/archived_report_generator_test.rb
foreman_inventory_upload-1.0.1 test/unit/archived_report_generator_test.rb
foreman_inventory_upload-0.9.0 test/unit/archived_report_generator_test.rb
foreman_inventory_upload-1.0.0 test/unit/archived_report_generator_test.rb