(t *testing.T)
| 101 | } |
| 102 | |
| 103 | func TestApplierBuildDMLEventQuery(t *testing.T) { |
| 104 | columns := sql.NewColumnList([]string{"id", "item_id"}) |
| 105 | columnValues := sql.ToColumnValues([]interface{}{123456, 42}) |
| 106 | |
| 107 | migrationContext := base.NewMigrationContext() |
| 108 | migrationContext.DatabaseName = "test" |
| 109 | migrationContext.OriginalTableName = "test" |
| 110 | migrationContext.OriginalTableColumns = columns |
| 111 | migrationContext.SharedColumns = columns |
| 112 | migrationContext.MappedSharedColumns = columns |
| 113 | migrationContext.UniqueKey = &sql.UniqueKey{ |
| 114 | Name: t.Name(), |
| 115 | Columns: *columns, |
| 116 | } |
| 117 | |
| 118 | applier := NewApplier(migrationContext) |
| 119 | applier.prepareQueries() |
| 120 | |
| 121 | t.Run("delete", func(t *testing.T) { |
| 122 | binlogEvent := &binlog.BinlogDMLEvent{ |
| 123 | DatabaseName: "test", |
| 124 | DML: binlog.DeleteDML, |
| 125 | WhereColumnValues: columnValues, |
| 126 | } |
| 127 | |
| 128 | res := applier.buildDMLEventQuery(binlogEvent) |
| 129 | require.Len(t, res, 1) |
| 130 | require.NoError(t, res[0].err) |
| 131 | require.Equal(t, `delete /* gh-ost `+"`test`.`_test_gho`"+` */ |
| 132 | from |
| 133 | `+"`test`.`_test_gho`"+` |
| 134 | where |
| 135 | ((`+"`id`"+` = ?) and (`+"`item_id`"+` = ?))`, |
| 136 | strings.TrimSpace(res[0].query)) |
| 137 | require.Len(t, res[0].args, 2) |
| 138 | require.Equal(t, 123456, res[0].args[0]) |
| 139 | require.Equal(t, 42, res[0].args[1]) |
| 140 | }) |
| 141 | |
| 142 | t.Run("insert", func(t *testing.T) { |
| 143 | binlogEvent := &binlog.BinlogDMLEvent{ |
| 144 | DatabaseName: "test", |
| 145 | DML: binlog.InsertDML, |
| 146 | NewColumnValues: columnValues, |
| 147 | } |
| 148 | res := applier.buildDMLEventQuery(binlogEvent) |
| 149 | require.Len(t, res, 1) |
| 150 | require.NoError(t, res[0].err) |
| 151 | require.Equal(t, |
| 152 | `insert /* gh-ost `+"`test`.`_test_gho`"+` */ ignore |
| 153 | into |
| 154 | `+"`test`.`_test_gho`"+` |
| 155 | `+"(`id`, `item_id`)"+` |
| 156 | values |
| 157 | (?, ?)`, |
| 158 | strings.TrimSpace(res[0].query)) |
| 159 | require.Len(t, res[0].args, 2) |
| 160 | require.Equal(t, 123456, res[0].args[0]) |
nothing calls this directly
no test coverage detected
searching dependent graphs…