Sha256: fe8dc966d583d862067e5c924893ae7cdebe931fe4de56b164766f21229b274b

Contents?: true

Size: 1.29 KB

Versions: 68

Compression:

Stored size: 1.29 KB

Contents

require 'test_plugin_helper'

class InsightsStatusCleanerTest < ActiveSupport::TestCase
  setup do
    @host1 = FactoryBot.create(:host)
    @host2 = FactoryBot.create(:host)

    InsightsClientReportStatus.find_or_initialize_by(host_id: @host1.id).update(status: InsightsClientReportStatus::NO_REPORT, 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)

    @host1.refresh_global_status!
    @host2.refresh_global_status!
  end

  test 'Cleans hosts by search condition' do
    assert_equal HostStatus::Global::ERROR, @host1.global_status
    assert_equal HostStatus::Global::ERROR, @host2.global_status

    instance = ForemanRhCloud::InsightsStatusCleaner.new
    actual_count = instance.clean("name = #{@host1.name}")

    @host1.reload
    @host2.refresh_global_status!

    assert_equal 1, actual_count
    assert_equal HostStatus::Global::OK, @host1.global_status
    assert_equal HostStatus::Global::ERROR, @host2.global_status
    assert InsightsClientReportStatus.where(host_id: @host1.id).empty?
    refute InsightsClientReportStatus.where(host_id: @host2.id).empty?
  end
end

Version data entries

68 entries across 68 versions & 1 rubygems

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