test/plugin/test_out_mixpanel.rb in fluent-plugin-mixpanel-0.0.3 vs test/plugin/test_out_mixpanel.rb in fluent-plugin-mixpanel-0.0.4

- old
+ new

@@ -9,15 +9,14 @@ end CONFIG = %[ project_token test_token distinct_id_key user_id - event_key event ] def create_driver(conf = CONFIG) - Fluent::Test::BufferedOutputTestDriver.new(Fluent::MixpanelOutput).configure(conf) + Fluent::Test::BufferedOutputTestDriver.new(Fluent::MixpanelOutput, 'mixpanel.test').configure(conf) end def stub_mixpanel(url="https://api.mixpanel.com/track") stub_request(:post, url).with do |req| body = URI.decode_www_form(req.body) @@ -32,29 +31,39 @@ def sample_record { user_id: "123", event: "event1", key1: "value1", key2: "value2" } end def test_configure - d = create_driver + d = create_driver(CONFIG + "event_key event") assert_equal 'test_token', d.instance.project_token assert_equal 'user_id', d.instance.distinct_id_key assert_equal 'event', d.instance.event_key end def test_configure_with_ip_key - d = create_driver(CONFIG + 'ip_key ip') + d = create_driver(CONFIG + "event_key event\n ip_key ip") assert_equal 'test_token', d.instance.project_token assert_equal 'user_id', d.instance.distinct_id_key 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") + + 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 - d = create_driver + d = create_driver(CONFIG + "event_key event") 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'] @@ -64,11 +73,11 @@ assert_equal "value2", @out[0]['properties']['key2'] end def test_write_multi_request stub_mixpanel - d = create_driver + d = create_driver(CONFIG + "event_key event") time1 = Time.new('2014-01-01T01:23:45+00:00') time2 = Time.new('2014-01-02T01:23:45+00:00') d.emit(sample_record, time1) d.emit(sample_record.merge(key3: "value3"), time2) @@ -88,11 +97,11 @@ assert_equal "value2", @out[1]['properties']['key2'] end def test_write_with_ip_key stub_mixpanel - d = create_driver(CONFIG + 'ip_key ip_address') + d = create_driver(CONFIG + "event_key event\n ip_key ip_address") time = Time.new('2014-01-01T01:23:45+00:00') d.emit(sample_record.merge('ip_address' => '192.168.0.2'), time) d.run assert_equal "123", @out[0]['properties']['distinct_id'] @@ -101,12 +110,40 @@ 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 + 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 + stub_mixpanel + 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_request_error stub_mixpanel_unavailable - d = create_driver + d = create_driver(CONFIG + "event_key event") d.emit(sample_record) assert_raise(Mixpanel::ConnectionError) { d.run } end