Sha256: 4e1282fc14f34c3fcd9c0278533f6738f4a10b3ace42ee978d969dfef1280320

Contents?: true

Size: 1.83 KB

Versions: 68

Compression:

Stored size: 1.83 KB

Contents

require 'test_plugin_helper'
require 'foreman_tasks/test_helpers'

class InsightsClientStatusAgingTest < ActiveSupport::TestCase
  include ForemanTasks::TestHelpers::WithInThreadExecutor

  setup do
    User.current = User.find_by(login: 'secret_admin')

    @host1 = FactoryBot.create(:host)
    @host2 = FactoryBot.create(:host)
    @host3 = FactoryBot.create(:host)
    @host4 = FactoryBot.create(:host)

    @hosts = [@host1, @host2, @host3, @host4]
  end

  test 'stale statuses should change' do
    InsightsClientReportStatus.find_or_initialize_by(host_id: @host1.id).update(status: InsightsClientReportStatus::REPORTING, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
    InsightsClientReportStatus.find_or_initialize_by(host_id: @host2.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL + 1.day)
    InsightsClientReportStatus.find_or_initialize_by(host_id: @host3.id).update(status: InsightsClientReportStatus::REPORTING, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)
    InsightsClientReportStatus.find_or_initialize_by(host_id: @host4.id).update(status: InsightsClientReportStatus::NO_REPORT, reported_at: Time.now - InsightsClientReportStatus::REPORT_INTERVAL - 1.day)

    ForemanTasks.sync_task(InsightsCloud::Async::InsightsClientStatusAging)

    @hosts.each(&:reload)

    assert_equal InsightsClientReportStatus::REPORTING, @host1.get_status(InsightsClientReportStatus).status
    assert_equal InsightsClientReportStatus::NO_REPORT, @host2.get_status(InsightsClientReportStatus).status
    assert_equal InsightsClientReportStatus::NO_REPORT, @host3.get_status(InsightsClientReportStatus).status
    assert_equal InsightsClientReportStatus::NO_REPORT, @host4.get_status(InsightsClientReportStatus).status
  end
end

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
foreman_rh_cloud-11.0.3 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-9.0.59 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-11.0.2 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-11.0.1 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-11.0.0 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-9.0.58 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-10.0.2 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-9.0.57 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-10.0.1 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-9.0.56 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-9.0.55 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-9.0.54 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-9.0.53 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-9.0.52 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-8.0.52 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-9.0.51 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-8.0.51 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-7.0.48 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-7.0.47 test/jobs/insights_client_status_aging_test.rb
foreman_rh_cloud-8.0.50 test/jobs/insights_client_status_aging_test.rb