Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer committed Dec 22, 2020
1 parent 9d3d45f commit 052b6e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lightning/restore/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

tmysql "github.com/go-sql-driver/mysql"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/parser"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/format"
Expand Down Expand Up @@ -171,6 +172,9 @@ loopCreate:
"create table",
logger.With(zap.String("table", common.UniqueTable(database, tbl))),
)
failpoint.Inject("sqlCreateStmts", func() {
err = errors.Errorf("create %s failed", tbl)
})
if err != nil {
break loopCreate
}
Expand Down
19 changes: 19 additions & 0 deletions lightning/restore/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/go-sql-driver/mysql"
. "github.com/pingcap/check"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
tmysql "github.com/pingcap/parser/mysql"
Expand Down Expand Up @@ -224,6 +225,24 @@ func (s *tidbSuite) TestInitSchemaSyntaxError(c *C) {
c.Assert(err, NotNil)
}

func (s *tidbSuite) TestInitSchemaErrorLost(c *C) {
ctx := context.Background()

s.mockDB.
ExpectExec("CREATE DATABASE IF NOT EXISTS `db`").
WillReturnResult(sqlmock.NewResult(1, 1))
s.mockDB.
ExpectClose()

failpoint.Enable("github.com/pingcap/tidb-lightning/lightning/restore/GetRlimitValue", "return")
err := InitSchema(ctx, s.tiGlue, "db", map[string]string{
"t1": "create table `t1` (a int);",
, "t2": "create table t2 (a int primary key, b varchar(200));",
})
failpoint.Disable("github.com/pingcap/tidb-lightning/lightning/restore/GetRlimitValue")
c.Assert(err, ErrorMatches, "create t1 failed")
}

func (s *tidbSuite) TestInitSchemaUnsupportedSchemaError(c *C) {
ctx := context.Background()

Expand Down

0 comments on commit 052b6e8

Please sign in to comment.