spec/flydata/command/sync_spec.rb in flydata-0.4.0 vs spec/flydata/command/sync_spec.rb in flydata-0.4.1

- old
+ new

@@ -31,11 +31,12 @@ "tag_name"=>"flydata.a458c641_dp52.flydata_mysql", "tag_name_dev"=>"flydata.a458c641_dp52.flydata_mysql.dev", "data_port_key"=>"a458c641", "mysql_data_entry_preference" => { "host"=>"localhost", "port"=>3306, "username"=>"masashi", - "password"=>"welcome", "database"=>"sync_test", "tables"=>["table1", " table2"], + "password"=>"welcome", "database"=>"sync_test", "tables"=>["table1", "table2"], + "invalid_tables"=>["table3"], "mysqldump_dir"=>default_mysqldump_dir, "forwarder" => "tcpforwarder", "data_servers"=>"localhost:9905" } } end let(:mysql_table_columns) { @@ -134,11 +135,12 @@ end end describe '#do_generate_table_ddl' do before do allow(subject).to receive(:data_entry).and_return(default_data_entry) - subject.send(:set_current_tables) + allow_any_instance_of(Flydata::Api::DataEntry).to receive(:update_table_validity).and_return(true) + subject.send(:set_current_tables, nil, include_invalid_tables: true) end shared_examples 'throws an error' do it "throws an error" do expect { subject.send(:do_generate_table_ddl, default_data_entry) @@ -146,11 +148,11 @@ end end context 'with full options' do it 'issues mysqldump command with expected parameters' do expect(Open3).to receive(:popen3).with( - 'mysqldump -h localhost -P 3306 -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2') + 'mysqldump -h localhost -P 3306 -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table3') subject.send(:do_generate_table_ddl, default_data_entry) end end context 'without_host' do before do @@ -168,21 +170,21 @@ before do default_data_entry['mysql_data_entry_preference'].delete('port') end it "uses the default port" do expect(Open3).to receive(:popen3).with( - 'mysqldump -h localhost -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2') + 'mysqldump -h localhost -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table3') subject.send(:do_generate_table_ddl, default_data_entry) end end context 'with_port_override' do before do default_data_entry['mysql_data_entry_preference']['port'] = 1234 end it "uses the specified port" do expect(Open3).to receive(:popen3).with( - 'mysqldump -h localhost -P 1234 -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2') + 'mysqldump -h localhost -P 1234 -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table3') subject.send(:do_generate_table_ddl, default_data_entry) end end context 'without_username' do before do @@ -200,22 +202,22 @@ before do default_data_entry['mysql_data_entry_preference'].delete('password') end it "call mysqldump without MYSQL_PW set" do expect(Open3).to receive(:popen3).with( - 'mysqldump -h localhost -P 3306 -umasashi --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2') + 'mysqldump -h localhost -P 3306 -umasashi --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table3') subject.send(:do_generate_table_ddl, default_data_entry) end end context 'with password containing symbols' do before do default_data_entry['mysql_data_entry_preference'].delete('password') default_data_entry['mysql_data_entry_preference']['password']="welcome&!@^@#^" end it "call mysqldump with MYSQL_PW set with correct symbols" do expect(Open3).to receive(:popen3).with( - 'mysqldump -h localhost -P 3306 -umasashi -p"welcome&!@^@#^" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2') + 'mysqldump -h localhost -P 3306 -umasashi -p"welcome&!@^@#^" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table3') subject.send(:do_generate_table_ddl, default_data_entry) end end context 'without_database' do before do @@ -227,20 +229,20 @@ before do default_data_entry['mysql_data_entry_preference']['database'] = "" end include_examples 'throws an error' end - context 'without_tables' do - before do - default_data_entry['mysql_data_entry_preference'].delete('tables') - end - include_examples 'throws an error' - end context 'with empty tables' do + let(:sync_cmd) { described_class.new } before do - default_data_entry['mysql_data_entry_preference']['tables'] = "" + default_data_entry['mysql_data_entry_preference']['tables'] = [] + default_data_entry['mysql_data_entry_preference']['invalid_tables'] = [] + allow(sync_cmd).to receive(:data_entry).and_return(default_data_entry) + sync_cmd.send(:set_current_tables, nil, include_invalid_tables: true) end - include_examples 'throws an error' + it 'should raise error' do + expect{sync_cmd.send(:do_generate_table_ddl, default_data_entry)}.to raise_error + end end end describe '#convert_to_flydata_values' do subject { subject_object.send(:convert_to_flydata_values, mysql_table, values) } let(:values) { [4, 'John', nil, '0xC0448200', nil, nil] }