spec/flydata/command/sync_spec.rb in flydata-0.5.4 vs spec/flydata/command/sync_spec.rb in flydata-0.5.5
- old
+ new
@@ -31,12 +31,13 @@
"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", "table4"],
"invalid_tables"=>["table3"],
+ "new_tables"=>["table4"],
"mysqldump_dir"=>default_mysqldump_dir, "forwarder" => "tcpforwarder",
"data_servers"=>"localhost:9905" }
}
end
let(:mysql_table_columns) {
@@ -89,12 +90,13 @@
let (:default_backup) { double('default_backup') }
let (:target_tables) { ["test_table_1"] }
let (:db_byte) { 1 }
let (:disk_byte) { 100 }
before do
- expect(subject).to receive(:flydata).and_return(flydata)
+ expect(subject).to receive(:flydata).and_return(flydata).at_least(:once)
expect(flydata).to receive(:data_port).and_return(dp)
+ allow(flydata).to receive(:data_entry).and_return(default_data_entry)
expect(dp).to receive(:get).and_return(default_data_port)
allow(File).to receive(:exists?).and_return(false)
expect(default_sync_fm).to receive(:load_dump_pos).and_return(default_dump_pos)
expect(default_sync_fm).to receive(:dump_file_path).and_return(default_fp)
expect(default_sync_fm).to receive(:backup_dir).and_return(default_backup)
@@ -108,11 +110,11 @@
end
context 'with no stream option' do
before do
expect(default_sync_fm).to receive(:save_sync_info).once
expect(subject).to receive(:free_disk_space).and_return(disk_byte)
- expect(File).to receive(:dirname)
+ expect(File).to receive(:dirname)
end
it 'will export to dump file' do
expect(subject).to receive(:call_block_or_return_io)
Flydata::Parser::Mysql::MysqlDumpGeneratorNoMasterData.any_instance.should_receive(:dump).with(default_fp)
@@ -138,11 +140,11 @@
end
describe '#do_generate_table_ddl' do
before do
allow(subject).to receive(:data_entry).and_return(default_data_entry)
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)
+ subject.send(:set_current_tables, nil, include_all_tables: true)
end
shared_examples 'throws an error' do
it "throws an error" do
expect {
subject.send(:do_generate_table_ddl, default_data_entry)
@@ -150,11 +152,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 table3')
+ 'mysqldump -h localhost -P 3306 -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table4 table3')
subject.send(:do_generate_table_ddl, default_data_entry)
end
end
context 'without_host' do
before do
@@ -172,21 +174,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 table3')
+ 'mysqldump -h localhost -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table4 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 table3')
+ 'mysqldump -h localhost -P 1234 -umasashi -p"welcome" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table4 table3')
subject.send(:do_generate_table_ddl, default_data_entry)
end
end
context 'without_username' do
before do
@@ -204,22 +206,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 table3')
+ 'mysqldump -h localhost -P 3306 -umasashi --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table4 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 table3')
+ 'mysqldump -h localhost -P 3306 -umasashi -p"welcome&!@^@#^" --default-character-set=utf8 --protocol=tcp -d sync_test table1 table2 table4 table3')
subject.send(:do_generate_table_ddl, default_data_entry)
end
end
context 'without_database' do
before do
@@ -236,11 +238,12 @@
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']['invalid_tables'] = []
+ default_data_entry['mysql_data_entry_preference']['new_tables'] = []
allow(sync_cmd).to receive(:data_entry).and_return(default_data_entry)
- sync_cmd.send(:set_current_tables, nil, include_invalid_tables: true)
+ sync_cmd.send(:set_current_tables, nil, include_all_tables: true)
end
it 'should raise error' do
expect{sync_cmd.send(:do_generate_table_ddl, default_data_entry)}.to raise_error
end
end