Skip to content

Commit

Permalink
Merge pull request #121 from shuhaowu/test-escaped-data
Browse files Browse the repository at this point in the history
Test copying escaped data
  • Loading branch information
shuhaowu authored Jun 27, 2019
2 parents 2605345 + 224afea commit e7d15e2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/integration/types_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,34 @@ def test_json_data
assert_equal expected_row, row
end
end

def test_escaped_data
[source_db, target_db].each do |db|
db.query("CREATE DATABASE IF NOT EXISTS #{DEFAULT_DB}")
db.query("CREATE TABLE IF NOT EXISTS #{DEFAULT_FULL_TABLE_NAME} (id bigint(20) not null auto_increment, data1 TEXT, data2 VARCHAR(255), data3 BLOB, primary key(id))")
end

source_db.query("INSERT INTO #{DEFAULT_FULL_TABLE_NAME} (id, data1, data2, data3) VALUES (1, '''', '''', _binary'''')")

ghostferry = new_ghostferry(MINIMAL_GHOSTFERRY)

ghostferry.on_status(Ghostferry::Status::BINLOG_STREAMING_STARTED) do
source_db.query("INSERT INTO #{DEFAULT_FULL_TABLE_NAME} (id, data1, data2, data3) VALUES (2, '''', '''', _binary'''')")
source_db.query("UPDATE #{DEFAULT_FULL_TABLE_NAME} SET data1 = 'test', data2 = 'test', data3 = _binary'test' WHERE id = 1")
source_db.query("UPDATE #{DEFAULT_FULL_TABLE_NAME} SET data1 = '''', data2 = '''', data3 = _binary'''' WHERE id = 1")
source_db.query("DELETE FROM #{DEFAULT_FULL_TABLE_NAME} WHERE id = 2")
end

ghostferry.run

assert_test_table_is_identical
res = target_db.query("SELECT * FROM #{DEFAULT_FULL_TABLE_NAME}")
assert_equal 1, res.count
res.each do |row|
assert_equal 1, row["id"]
assert_equal "'", row["data1"]
assert_equal "'", row["data2"]
assert_equal "'", row["data3"]
end
end
end
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ def assert_test_table_is_identical
assert_equal(
source[DEFAULT_FULL_TABLE_NAME][:row_count],
target[DEFAULT_FULL_TABLE_NAME][:row_count],
"source and target row count don't match",
)

assert_equal(
source[DEFAULT_FULL_TABLE_NAME][:checksum],
target[DEFAULT_FULL_TABLE_NAME][:checksum],
"source and target checksum don't match",
)
end

Expand Down

0 comments on commit e7d15e2

Please sign in to comment.