test/plugin/test_out_mackerel.rb in fluent-plugin-mackerel-0.0.6 vs test/plugin/test_out_mackerel.rb in fluent-plugin-mackerel-0.0.7
- old
+ new
@@ -44,10 +44,25 @@
metrics_name service.${out_key}
out_keys val1,val2,val3
origin example.domain
]
+ CONFIG_NO_OUT_KEYS = %[
+ type mackerel
+ api_key 123456
+ hostid xyz
+ metrics_name service.${out_key}
+ ]
+
+ CONFIG_OUT_KEY_PATTERN = %[
+ type mackerel
+ api_key 123456
+ hostid xyz
+ metrics_name service.${out_key}
+ out_key_pattern ^val[0-9]$
+ ]
+
def create_driver(conf = CONFIG, tag='test')
Fluent::Test::BufferedOutputTestDriver.new(Fluent::MackerelOutput, tag).configure(conf)
end
def test_configure
@@ -62,10 +77,14 @@
assert_raise(Fluent::ConfigError) {
d = create_driver(CONFIG_BLANK_METRICS)
}
+ assert_raise(Fluent::ConfigError) {
+ d = create_driver(CONFIG_NO_OUT_KEYS)
+ }
+
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'
@@ -74,10 +93,14 @@
assert_equal d.instance.instance_variable_get(:@api_key), '123456'
assert_equal d.instance.instance_variable_get(:@hostid), 'xyz'
assert_equal d.instance.instance_variable_get(:@metrics_name), 'service.${out_key}'
assert_equal d.instance.instance_variable_get(:@out_keys), ['val1','val2','val3']
assert_equal d.instance.instance_variable_get(:@flush_interval), 60
+
+ d = create_driver(CONFIG_OUT_KEY_PATTERN)
+ assert_match d.instance.instance_variable_get(:@out_key_pattern), "val1"
+ assert_no_match d.instance.instance_variable_get(:@out_key_pattern), "foo"
end
def test_write
d = create_driver()
mock(d.instance.mackerel).post_metrics([
@@ -94,9 +117,22 @@
ENV["TZ"]="Asia/Tokyo"
t = Time.strptime('2014-05-14 01:11:38', '%Y-%m-%d %T')
d.emit({'val1' => 1, 'val2' => 2, 'val3' => 3, 'val4' => 4}, t)
d.emit({'val1' => 5, 'val2' => 6, 'val3' => 7, 'val4' => 8}, t)
d.emit({'val1' => 9, 'val2' => 10}, t)
+ d.run()
+ end
+
+ def test_write_pattern
+ d = create_driver(CONFIG_OUT_KEY_PATTERN)
+ 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"},
+ ])
+
+ 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
end