Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
add unit test for the situation that both filesize and rows are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
lichunzhu committed Nov 3, 2020
1 parent da4cf7b commit ffcea13
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions v4/export/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,63 @@ func (s *testDumpSuite) TestWriteTableDataWithFileSize(c *C) {
}
}

func (s *testDumpSuite) TestWriteTableDataWithFileSizeAndRows(c *C) {
dir := c.MkDir()

ctx := context.Background()

config := DefaultConfig()
config.OutputDirPath = dir
config.FileSize = 50
config.Rows = 4
err := adjustConfig(ctx, config)
c.Assert(err, IsNil)
specCmts := []string{
"/*!40101 SET NAMES binary*/;",
"/*!40014 SET FOREIGN_KEY_CHECKS=0*/;",
}
config.FileSize += uint64(len(specCmts[0]) + 1)
config.FileSize += uint64(len(specCmts[1]) + 1)
config.FileSize += uint64(len("INSERT INTO `employees` VALUES\n"))

simpleWriter, err := NewSimpleWriter(config)
c.Assert(err, IsNil)
writer := SQLWriter{SimpleWriter: simpleWriter}

data := [][]driver.Value{
{"1", "male", "bob@mail.com", "020-1234", nil},
{"2", "female", "sarah@mail.com", "020-1253", "healthy"},
{"3", "male", "john@mail.com", "020-1256", "healthy"},
{"4", "female", "sarah@mail.com", "020-1235", "healthy"},
}
colTypes := []string{"INT", "SET", "VARCHAR", "VARCHAR", "TEXT"}
tableIR := newMockTableIR("test", "employee", data, specCmts, colTypes)
err = writer.WriteTableData(ctx, tableIR)
c.Assert(err, IsNil)

cases := map[string]string{
"test.employee.0000000000000.sql": "/*!40101 SET NAMES binary*/;\n" +
"/*!40014 SET FOREIGN_KEY_CHECKS=0*/;\n" +
"INSERT INTO `employee` VALUES\n" +
"(1,'male','bob@mail.com','020-1234',NULL),\n" +
"(2,'female','sarah@mail.com','020-1253','healthy');\n",
"test.employee.0000000000001.sql": "/*!40101 SET NAMES binary*/;\n" +
"/*!40014 SET FOREIGN_KEY_CHECKS=0*/;\n" +
"INSERT INTO `employee` VALUES\n" +
"(3,'male','john@mail.com','020-1256','healthy'),\n" +
"(4,'female','sarah@mail.com','020-1235','healthy');\n",
}

for p, expected := range cases {
p := path.Join(dir, p)
_, err = os.Stat(p)
c.Assert(err, IsNil)
bytes, err := ioutil.ReadFile(p)
c.Assert(err, IsNil)
c.Assert(string(bytes), Equals, expected)
}
}

func (s *testDumpSuite) TestWriteTableDataWithStatementSize(c *C) {
dir := c.MkDir()

Expand Down

0 comments on commit ffcea13

Please sign in to comment.