test/plugin/test_out_mixpanel.rb in fluent-plugin-mixpanel-0.0.6 vs test/plugin/test_out_mixpanel.rb in fluent-plugin-mixpanel-0.0.7
- old
+ new
@@ -13,10 +13,11 @@
distinct_id_key user_id
]
IMPORT_CONFIG = CONFIG + %[ api_key test_api_key
use_import true
+ use_legacy_prefix_behavior false
]
def create_driver(conf = CONFIG)
Fluent::Test::BufferedOutputTestDriver.new(Fluent::MixpanelOutput, 'mixpanel.test').configure(conf)
end
@@ -56,16 +57,15 @@
assert_equal 'event', d.instance.event_key
assert_equal 'ip', d.instance.ip_key
end
def test_configure_with_event_map_tag
- d = create_driver(CONFIG + "remove_tag_prefix mixpanel\n event_map_tag true")
+ d = create_driver(CONFIG + "event_map_tag true")
assert_equal 'test_token', d.instance.project_token
assert_equal 'user_id', d.instance.distinct_id_key
assert_equal nil, d.instance.event_key
- assert_equal 'mixpanel', d.instance.remove_tag_prefix
assert_equal true.to_s, d.instance.event_map_tag
end
def test_write
stub_mixpanel
@@ -119,36 +119,108 @@
assert_equal "192.168.0.2", @out[0]['properties']['ip']
assert_equal "value1", @out[0]['properties']['key1']
assert_equal "value2", @out[0]['properties']['key2']
end
- def test_write_with_event_map_tag
+ def test_write_with_no_tag_manipulation
stub_mixpanel
- d = create_driver(CONFIG + "remove_tag_prefix mixpanel\n event_map_tag true")
+ d = create_driver(CONFIG + "event_map_tag true")
time = Time.new('2014-01-01T01:23:45+00:00')
d.emit(sample_record, time)
d.run
+ assert_equal "123", @out[0]['properties']['distinct_id']
+ assert_equal "mixpanel.test", @out[0]['event']
+ assert_equal time.to_i, @out[0]['properties']['time']
+ assert_equal "value1", @out[0]['properties']['key1']
+ assert_equal "value2", @out[0]['properties']['key2']
+ end
+
+ def test_write_with_event_map_tag_removing_prefix
+ stub_mixpanel
+ d = create_driver(CONFIG + "remove_tag_prefix mixpanel.\n event_map_tag true")
+ time = Time.new('2014-01-01T01:23:45+00:00')
+ d.emit(sample_record, time)
+ d.run
+
assert_equal "123", @out[0]['properties']['distinct_id']
assert_equal "test", @out[0]['event']
assert_equal time.to_i, @out[0]['properties']['time']
assert_equal "value1", @out[0]['properties']['key1']
assert_equal "value2", @out[0]['properties']['key2']
end
- def test_write_with_no_remove_tag_prefix
+ def test_write_with_event_map_tag_removing_prefix_LEGACY
stub_mixpanel
- d = create_driver(CONFIG + "event_map_tag true")
+ d = create_driver(CONFIG + "remove_tag_prefix mixpanel\n event_map_tag true\n use_legacy_prefix_behavior true")
time = Time.new('2014-01-01T01:23:45+00:00')
d.emit(sample_record, time)
d.run
- assert_equal "123", @out[0]['properties']['distinct_id']
- assert_equal "mixpanel.test", @out[0]['event']
- assert_equal time.to_i, @out[0]['properties']['time']
- assert_equal "value1", @out[0]['properties']['key1']
- assert_equal "value2", @out[0]['properties']['key2']
+ assert_equal "123", @out[0]['properties']['distinct_id']
+ assert_equal "test", @out[0]['event']
+ assert_equal time.to_i, @out[0]['properties']['time']
+ assert_equal "value1", @out[0]['properties']['key1']
+ assert_equal "value2", @out[0]['properties']['key2']
end
+
+ def test_write_with_event_map_tag_removing_prefix_LEGACY_with_dot
+ stub_mixpanel
+ d = create_driver(CONFIG + "remove_tag_prefix mixpanel.\n event_map_tag true\n use_legacy_prefix_behavior true")
+ time = Time.new('2014-01-01T01:23:45+00:00')
+ d.emit(sample_record, time)
+ d.run
+
+ assert_equal "123", @out[0]['properties']['distinct_id']
+ assert_equal "test", @out[0]['event']
+ assert_equal time.to_i, @out[0]['properties']['time']
+ assert_equal "value1", @out[0]['properties']['key1']
+ assert_equal "value2", @out[0]['properties']['key2']
+ end
+
+ def test_write_with_event_map_tag_removing_suffix
+ stub_mixpanel
+ d = create_driver(CONFIG + "remove_tag_suffix .test\n event_map_tag true")
+ time = Time.new('2014-01-01T01:23:45+00:00')
+ d.emit(sample_record, time)
+ d.run
+
+ assert_equal "123", @out[0]['properties']['distinct_id']
+ assert_equal "mixpanel", @out[0]['event']
+ assert_equal time.to_i, @out[0]['properties']['time']
+ assert_equal "value1", @out[0]['properties']['key1']
+ assert_equal "value2", @out[0]['properties']['key2']
+ end
+
+ def test_write_with_event_map_tag_adding_prefix
+ stub_mixpanel
+ d = create_driver(CONFIG + "add_tag_prefix foo.\n event_map_tag true")
+ time = Time.new('2014-01-01T01:23:45+00:00')
+ d.emit(sample_record, time)
+ d.run
+
+ assert_equal "123", @out[0]['properties']['distinct_id']
+ assert_equal "foo.mixpanel.test", @out[0]['event']
+ assert_equal time.to_i, @out[0]['properties']['time']
+ assert_equal "value1", @out[0]['properties']['key1']
+ assert_equal "value2", @out[0]['properties']['key2']
+ end
+
+ def test_write_with_event_map_tag_adding_suffix
+ stub_mixpanel
+ d = create_driver(CONFIG + "add_tag_suffix .foo\n event_map_tag true")
+ time = Time.new('2014-01-01T01:23:45+00:00')
+ d.emit(sample_record, time)
+ d.run
+
+ assert_equal "123", @out[0]['properties']['distinct_id']
+ assert_equal "mixpanel.test.foo", @out[0]['event']
+ assert_equal time.to_i, @out[0]['properties']['time']
+ assert_equal "value1", @out[0]['properties']['key1']
+ assert_equal "value2", @out[0]['properties']['key2']
+ end
+
+
def test_write_ignore_special_event
stub_mixpanel
d = create_driver(CONFIG + "event_key event")
time = Time.new('2014-01-01T01:23:45+00:00')