test/plugin/test_out_mixpanel.rb in fluent-plugin-mixpanel-0.0.5 vs test/plugin/test_out_mixpanel.rb in fluent-plugin-mixpanel-0.0.6

- old
+ new

@@ -11,10 +11,14 @@ CONFIG = %[ project_token test_token distinct_id_key user_id ] + IMPORT_CONFIG = CONFIG + %[ api_key test_api_key + use_import true + ] + def create_driver(conf = CONFIG) Fluent::Test::BufferedOutputTestDriver.new(Fluent::MixpanelOutput, 'mixpanel.test').configure(conf) end def stub_mixpanel(url="https://api.mixpanel.com/track") @@ -22,10 +26,14 @@ body = URI.decode_www_form(req.body) @out << JSON.load(Base64.decode64(body.assoc('data').last)) end.to_return(status: 200, body: JSON.generate({ status: 1 })) end + def stub_mixpanel_import + stub_mixpanel("https://api.mixpanel.com/import") + end + def stub_mixpanel_unavailable(url="https://api.mixpanel.com/track") stub_request(:post, url).to_return(status: 503, body: "Service Unavailable") end def sample_record @@ -73,12 +81,12 @@ assert_equal "value1", @out[0]['properties']['key1'] assert_equal "value2", @out[0]['properties']['key2'] end def test_write_multi_request - stub_mixpanel - d = create_driver(CONFIG + "event_key event") + stub_mixpanel_import + d = create_driver(IMPORT_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) @@ -104,11 +112,11 @@ 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'] - assert_equal "event1", @out[0]['event'] + assert_equal "event1", @out[0]['event'] assert_equal time.to_i, @out[0]['properties']['time'] 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 @@ -185,10 +193,10 @@ def test_request_error stub_mixpanel_unavailable d = create_driver(CONFIG + "event_key event") d.emit(sample_record) - assert_raise(Mixpanel::ConnectionError) { + assert_raise(Fluent::MixpanelOutput::MixpanelError) { d.run } end end