Skip to content

Commit

Permalink
util/kvencoder: add more unit test (#10008)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 committed Apr 8, 2019
1 parent 7b688ee commit bb23eac
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions util/kvencoder/kv_encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,41 @@ func (s *testKvEncoderSuite) TestAllocatorRebase(c *C) {
sql = "insert into t(id, a) values(2000, 'test')"
encoder.Encode(sql, tableID)
c.Assert(alloc.Base(), Equals, int64(2000))
c.Assert(alloc.End(), Equals, int64(2000)+step)
nextID, err := alloc.NextGlobalAutoID(tableID)
c.Assert(err, IsNil)
c.Assert(nextID, Equals, int64(2000)+step+1)
}

func (s *testKvEncoderSuite) TestError(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
alloc := NewAllocator()
encoder, err := New("test", alloc)
c.Assert(err, IsNil)
defer encoder.Close()
_, err = New("", alloc)
c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, "*Incorrect database name ''")

err = encoder.ExecDDLSQL("x")
c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, "*You have an error in your SQL syntax.*")

_, err = encoder.PrepareStmt("")
c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, "*Can not prepare multiple statements")
_, _, err = encoder.EncodePrepareStmt(0, 0, 0)
c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, "*Prepared statement not found")

encoder = &kvEncoder{}
err = encoder.SetSystemVariable("", "")
c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, ".*please new KvEncoder by kvencoder.New.*")
_, ok := encoder.GetSystemVariable("")
c.Assert(ok, IsFalse)
c.Assert(err, ErrorMatches, ".*please new KvEncoder by kvencoder.New.*")
}

func (s *testKvEncoderSuite) TestAllocatorRebaseSmaller(c *C) {
Expand Down

0 comments on commit bb23eac

Please sign in to comment.