# encoding: utf-8 require 'fluent_plugins_spec_helper' require 'in_postgresql_query_based_flydata' require 'flydata/fluent-plugins/flydata_plugin_ext/flydata_sync_query_based_shared_examples' module Fluent describe PostgresqlQueryBasedFlydataInput do let(:plugin) { PostgresqlQueryBasedFlydataInput.new } let(:default_config) { <"test_table", "status"=>"init_sync_completed"}, {"table_name"=>"test_table_1", "status"=>"init_sync_completed", "pk_override"=>["id1", "id2"]}, {"table_name"=>"test_table_2", "status"=>"init_sync_pending"}, {"table_name"=>"test_table_3", "omit_events"=>["delete"], "status"=>"init_sync_pending", "uk_as_pk"=>["uid"]}, {"table_name"=>"error_table_4", "omit_events"=>["delete"], "status"=>"init_sync_pending", "invalid_table_reason"=>"Table does not exist in the MySQL database"}] } before do create_file(TEST_POSITION_FILE, "1001:1001:\t\t") create_table_pos_file('test_table', '0') subject end after do delete_file(TEST_POSITION_FILE) end it 'sets data entry object' do expect(plugin.instance_variable_get(:@data_entry)).to eq( 'name' => 'test_name', 'type' => 'RedshiftMysqlDataEntry', 'postgresql_data_entry_preference' => { 'database' => 'test_db', 'tables' => 'test_table,test_table_1,test_table_2', 'tables_append_only' => 'test_table_3,error_table_4', 'pk_override' => {"test_table_1" => ["id1", "id2"], "test_table_3" => ["uid"]}, 'table_attributes' => table_attributes_array, 'host' => 'localhost', 'port' => 5433, 'username' => 'test_admin', 'password' => 'test_password', 'schema' => 'test_schema', } ) end it 'sets data tables as array' do expect(plugin.instance_variable_get(:@tables)).to eq(%w(test_table)) end it 'sets sync_fm' do expect(plugin.instance_variable_get(:@sync_fm)).to be_kind_of(Flydata::SyncFileManager) end it 'sets omit_events' do expect(plugin.instance_variable_get(:@omit_events)).to eq({'test_table_3' => [:delete, :truncate_table],'error_table_4' => [:delete, :truncate_table]}) end it 'sets pk_override' do expect(plugin.instance_variable_get(:@pk_override)).to eq({"test_table_1" => ["id1", "id2"], "test_table_3" => ["uid"]}) end it 'set table_attributes' do expect(plugin.instance_variable_get(:@table_attributes)).to eq(table_attributes_array) end it 'sets context' do expect(plugin.instance_variable_get(:@context)).to be_kind_of(Flydata::SourcePostgresql::PluginSupport::Context) end it 'sets client' do expect(plugin.instance_variable_get(:@client)).to be_kind_of(Flydata::SourcePostgresql::QueryBasedSync::Client) end end end end