test/plugin/test_out_mackerel.rb in fluent-plugin-mackerel-0.0.9 vs test/plugin/test_out_mackerel.rb in fluent-plugin-mackerel-0.1.0
- old
+ new
@@ -82,10 +82,32 @@
api_key 123456
out_keys val1,val2,val3
buffer_chunk_limit 1k
]
+ CONFIG_SERVICE = %[
+ type mackerel
+ api_key 123456
+ service xyz
+ out_keys val1,val2,val3
+ ]
+
+ CONFIG_SERVICE_REMOVE_PREFIX = %[
+ type mackerel
+ api_key 123456
+ service xyz
+ remove_prefix
+ out_keys val1,val2,val3
+ ]
+
+ CONFIG_INVALID_REMOVE_PREFIX = %[
+ type mackerel
+ api_key 123456
+ remove_prefix
+ out_keys val1,val2,val3
+ ]
+
def create_driver(conf = CONFIG, tag='test')
Fluent::Test::BufferedOutputTestDriver.new(Fluent::MackerelOutput, tag).configure(conf)
end
def test_configure
@@ -104,10 +126,14 @@
assert_raise(Fluent::ConfigError) {
d = create_driver(CONFIG_NO_OUT_KEYS)
}
+ assert_raise(Fluent::ConfigError) {
+ d = create_driver(CONFIG_INVALID_REMOVE_PREFIX)
+ }
+
d = create_driver(CONFIG_SMALL_FLUSH_INTERVAL)
assert_equal d.instance.instance_variable_get(:@flush_interval), 60
d = create_driver(CONFIG_ORIGIN)
assert_equal d.instance.instance_variable_get(:@origin), 'example.domain'
@@ -127,12 +153,13 @@
assert_equal d.instance.instance_variable_get(:@buffer_chunk_limit), Fluent::MackerelOutput::MAX_BUFFER_CHUNK_LIMIT
assert_equal d.instance.instance_variable_get(:@buffer_queue_limit), 4096
d = create_driver(CONFIG_BUFFER_LIMIT_IGNORE)
assert_equal d.instance.instance_variable_get(:@buffer_chunk_limit), Fluent::MackerelOutput::MAX_BUFFER_CHUNK_LIMIT
- end
+end
+
def test_write
d = create_driver()
mock(d.instance.mackerel).post_metrics([
{"hostId"=>"xyz", "value"=>1.0, "time"=>1399997498, "name"=>"custom.service.val1"},
{"hostId"=>"xyz", "value"=>2.0, "time"=>1399997498, "name"=>"custom.service.val2"},
@@ -168,9 +195,35 @@
def test_write_issue4
d = create_driver(CONFIG_FOR_ISSUE_4, tag='test.status')
mock(d.instance.mackerel).post_metrics([
{"hostId"=>"xyz", "value"=>1.0, "time"=>1399997498, "name"=>"custom.a-status-b.val1"},
{"hostId"=>"xyz", "value"=>2.0, "time"=>1399997498, "name"=>"custom.a-status-b.val2"},
+ ])
+
+ ENV["TZ"]="Asia/Tokyo"
+ t = Time.strptime('2014-05-14 01:11:38', '%Y-%m-%d %T')
+ d.emit({'val1' => 1, 'val2' => 2}, t)
+ d.run()
+ end
+
+ def test_service
+ d = create_driver(CONFIG_SERVICE)
+ mock(d.instance.mackerel).post_service_metrics('xyz', [
+ {"value"=>1.0, "time"=>1399997498, "name"=>"custom.val1"},
+ {"value"=>2.0, "time"=>1399997498, "name"=>"custom.val2"},
+ ])
+
+ ENV["TZ"]="Asia/Tokyo"
+ t = Time.strptime('2014-05-14 01:11:38', '%Y-%m-%d %T')
+ d.emit({'val1' => 1, 'val2' => 2, 'foo' => 3}, t)
+ d.run()
+ end
+
+ def test_service_remove_prefix
+ d = create_driver(CONFIG_SERVICE_REMOVE_PREFIX)
+ mock(d.instance.mackerel).post_service_metrics('xyz', [
+ {"value"=>1.0, "time"=>1399997498, "name"=>"val1"},
+ {"value"=>2.0, "time"=>1399997498, "name"=>"val2"},
])
ENV["TZ"]="Asia/Tokyo"
t = Time.strptime('2014-05-14 01:11:38', '%Y-%m-%d %T')
d.emit({'val1' => 1, 'val2' => 2, 'foo' => 3}, t)