2019-06-11 22:24:35 +00:00
|
|
|
require "inspec/utils/telemetry"
|
|
|
|
require "json"
|
|
|
|
require "helper"
|
2019-04-03 07:44:39 +00:00
|
|
|
|
|
|
|
class TestTelemetryDataSeries < Minitest::Test
|
|
|
|
def test_name
|
2019-06-11 22:24:35 +00:00
|
|
|
ds = Inspec::Telemetry::DataSeries.new("fizz")
|
2019-04-03 07:44:39 +00:00
|
|
|
refute_nil ds
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal "fizz", ds.name
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_data
|
2019-06-11 22:24:35 +00:00
|
|
|
ds = Inspec::Telemetry::DataSeries.new("fizz")
|
2019-04-03 07:44:39 +00:00
|
|
|
refute_nil ds.data
|
|
|
|
assert_kind_of Array, ds.data
|
|
|
|
assert_empty ds.data
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_data_append
|
2019-06-11 22:24:35 +00:00
|
|
|
ds = Inspec::Telemetry::DataSeries.new("fizz")
|
2019-04-03 07:44:39 +00:00
|
|
|
assert_empty ds.data
|
2019-06-11 22:24:35 +00:00
|
|
|
assert ds << "foo"
|
|
|
|
assert_equal ["foo"], ds.data
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_data_push_alias
|
2019-06-11 22:24:35 +00:00
|
|
|
ds = Inspec::Telemetry::DataSeries.new("fizz")
|
2019-04-03 07:44:39 +00:00
|
|
|
assert_empty ds.data
|
2019-06-11 22:24:35 +00:00
|
|
|
assert ds.push "bar"
|
|
|
|
assert_equal ["bar"], ds.data
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_h
|
2019-06-11 22:24:35 +00:00
|
|
|
ds = Inspec::Telemetry::DataSeries.new("fizz")
|
|
|
|
ds << "foo"
|
2019-04-03 07:44:39 +00:00
|
|
|
assert_kind_of Hash, ds.to_h
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal "fizz", ds.to_h[:name]
|
|
|
|
assert_equal ["foo"], ds.to_h[:data]
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_json
|
2019-06-11 22:24:35 +00:00
|
|
|
ds = Inspec::Telemetry::DataSeries.new("fizz")
|
|
|
|
ds << "foo"
|
2019-04-03 07:44:39 +00:00
|
|
|
assert_kind_of String, ds.to_json
|
2019-04-11 19:22:29 +00:00
|
|
|
assert_equal '{"name":"fizz","data":["foo"]}', ds.to_json
|
2019-04-03 07:44:39 +00:00
|
|
|
assert JSON.parse(ds.to_json)
|
|
|
|
end
|
2019-05-08 07:44:51 +00:00
|
|
|
|
|
|
|
def test_enabled
|
2019-06-11 22:24:35 +00:00
|
|
|
ds = Inspec::Telemetry::DataSeries.new("fizz")
|
2019-05-08 07:44:51 +00:00
|
|
|
assert ds.enabled?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_disable
|
2019-06-11 22:24:35 +00:00
|
|
|
ds = Inspec::Telemetry::DataSeries.new("fizz")
|
2019-05-08 07:44:51 +00:00
|
|
|
assert ds.enabled?
|
|
|
|
ds.disable
|
|
|
|
refute ds.enabled?
|
|
|
|
end
|
2019-04-03 07:44:39 +00:00
|
|
|
end
|