2019-06-11 22:24:35 +00:00
|
|
|
require "inspec/utils/telemetry"
|
|
|
|
require "helper"
|
2019-04-03 07:44:39 +00:00
|
|
|
|
|
|
|
class TestTelemetryCollector < Minitest::Test
|
|
|
|
def setup
|
|
|
|
@collector = Inspec::Telemetry::Collector.instance
|
2019-05-08 07:36:45 +00:00
|
|
|
@collector.reset!
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_collector_singleton
|
|
|
|
assert_equal Inspec::Telemetry::Collector.instance, @collector
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_data_series
|
2019-04-11 19:17:59 +00:00
|
|
|
assert_empty @collector.list_data_series
|
2019-06-11 22:24:35 +00:00
|
|
|
assert @collector.add_data_series(Inspec::Telemetry::DataSeries.new("/resource/File"))
|
2019-04-11 19:17:59 +00:00
|
|
|
refute_empty @collector.list_data_series
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_list_data_series
|
2019-04-11 18:47:42 +00:00
|
|
|
assert_empty @collector.list_data_series
|
2019-06-11 22:24:35 +00:00
|
|
|
@collector.add_data_series(Inspec::Telemetry::DataSeries.new("/resource/File"))
|
2019-04-11 18:47:42 +00:00
|
|
|
@collector.add_data_series(Inspec::Telemetry::DataSeries.new(:deprecation_group))
|
|
|
|
assert_equal 2, @collector.list_data_series.count
|
|
|
|
assert_equal 1, @collector.list_data_series.select { |d| d.name.eql?(:deprecation_group) }.count
|
|
|
|
assert_kind_of Array, @collector.list_data_series
|
|
|
|
assert_kind_of Inspec::Telemetry::DataSeries, @collector.list_data_series.first
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_find_or_create_data_series
|
|
|
|
dg = @collector.find_or_create_data_series(:deprecation_group)
|
|
|
|
assert_kind_of Inspec::Telemetry::DataSeries, dg
|
|
|
|
assert_equal :deprecation_group, dg.name
|
|
|
|
assert_equal @collector.find_or_create_data_series(:deprecation_group), dg
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_reset_singleton
|
2019-06-11 22:24:35 +00:00
|
|
|
data_series = Inspec::Telemetry::DataSeries.new("/resource/File")
|
2019-04-03 07:44:39 +00:00
|
|
|
@collector.add_data_series(data_series)
|
2019-05-08 07:36:45 +00:00
|
|
|
@collector.reset!
|
2019-04-03 07:44:39 +00:00
|
|
|
assert_equal 0, @collector.list_data_series.count
|
|
|
|
end
|
2019-05-03 23:07:24 +00:00
|
|
|
|
|
|
|
def test_telemetry_enabled
|
2019-06-11 22:24:35 +00:00
|
|
|
@collector.load_config(Inspec::Config.mock("enable_telemetry" => true))
|
2019-05-08 07:30:24 +00:00
|
|
|
assert @collector.telemetry_enabled?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_telemetry_disabled
|
2019-06-11 22:24:35 +00:00
|
|
|
@collector.load_config(Inspec::Config.mock("enable_telemetry" => false))
|
2019-05-08 02:06:38 +00:00
|
|
|
refute @collector.telemetry_enabled?
|
2019-05-08 07:30:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_disable_telemetry
|
2019-06-11 22:24:35 +00:00
|
|
|
@collector.load_config(Inspec::Config.mock("enable_telemetry" => true))
|
2019-05-03 23:07:24 +00:00
|
|
|
assert @collector.telemetry_enabled?
|
2019-05-08 07:30:24 +00:00
|
|
|
@collector.disable_telemetry
|
|
|
|
refute @collector.telemetry_enabled?
|
2019-05-03 23:07:24 +00:00
|
|
|
end
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|