2019-06-11 22:24:35 +00:00
|
|
|
require "inspec/utils/telemetry"
|
|
|
|
require "helper"
|
2019-04-03 07:44:39 +00:00
|
|
|
|
|
|
|
class TestTelemetryGlobalMethods < Minitest::Test
|
|
|
|
def setup
|
|
|
|
@collector = Inspec::Telemetry::Collector.instance
|
2019-06-11 22:24:35 +00:00
|
|
|
@collector.load_config(Inspec::Config.mock("enable_telemetry" => true))
|
2019-05-08 07:36:45 +00:00
|
|
|
@collector.reset!
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_record_telemetry_data
|
2019-06-11 22:24:35 +00:00
|
|
|
assert Inspec.record_telemetry_data(:deprecation_group, "serverspec_compat")
|
2019-04-03 07:44:39 +00:00
|
|
|
|
|
|
|
depgrp = @collector.find_or_create_data_series(:deprecation_group)
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal ["serverspec_compat"], depgrp.data
|
2019-04-03 07:44:39 +00:00
|
|
|
assert_equal :deprecation_group, depgrp.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_record_telemetry_data_with_block
|
|
|
|
Inspec.record_telemetry_data(:deprecation_group) do
|
2019-06-11 22:24:35 +00:00
|
|
|
"serverspec_compat"
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
depgrp = @collector.find_or_create_data_series(:deprecation_group)
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal ["serverspec_compat"], depgrp.data
|
2019-04-03 07:44:39 +00:00
|
|
|
assert_equal :deprecation_group, depgrp.name
|
|
|
|
end
|
2019-05-03 23:13:45 +00:00
|
|
|
|
|
|
|
def test_telemetry_disabled
|
|
|
|
@collector.load_config(Inspec::Config.mock(telemetry: false))
|
2019-06-11 22:24:35 +00:00
|
|
|
refute Inspec.record_telemetry_data(:deprecation_group, "serverspec_compat")
|
2019-05-03 23:13:45 +00:00
|
|
|
end
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|