Skip to content

Commit

Permalink
structure: improve package unit test code coverage to 86% (pingcap#10372
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tiancaiamao authored and zz-jason committed May 7, 2019
1 parent 4789904 commit e9482cf
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions structure/structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ func (s *testTxStructureSuite) TestString(c *C) {
c.Assert(err, IsNil)
c.Assert(v, IsNil)

tx1 := structure.NewStructure(txn, nil, []byte{0x01})
err = tx1.Set(key, value)
c.Assert(err, NotNil)

_, err = tx1.Inc(key, 1)
c.Assert(err, NotNil)

err = tx1.Clear(key)
c.Assert(err, NotNil)

err = txn.Commit(context.Background())
c.Assert(err, IsNil)
}
Expand Down Expand Up @@ -126,6 +136,9 @@ func (s *testTxStructureSuite) TestList(c *C) {
err = tx.LSet(key, 1, []byte("2"))
c.Assert(err, IsNil)

err = tx.LSet(key, 100, []byte("2"))
c.Assert(err, NotNil)

value, err = tx.LIndex(key, -1)
c.Assert(err, IsNil)
c.Assert(value, DeepEquals, []byte("3"))
Expand Down Expand Up @@ -175,6 +188,19 @@ func (s *testTxStructureSuite) TestList(c *C) {
c.Assert(err, IsNil)
c.Assert(l, Equals, int64(0))

tx1 := structure.NewStructure(txn, nil, []byte{0x01})
err = tx1.LPush(key, []byte("1"))
c.Assert(err, NotNil)

_, err = tx1.RPop(key)
c.Assert(err, NotNil)

err = tx1.LSet(key, 1, []byte("2"))
c.Assert(err, NotNil)

err = tx1.LClear(key)
c.Assert(err, NotNil)

err = txn.Commit(context.Background())
c.Assert(err, IsNil)
}
Expand All @@ -188,6 +214,8 @@ func (s *testTxStructureSuite) TestHash(c *C) {

key := []byte("a")

tx.EncodeHashAutoIDKeyValue(key, key, 5)

err = tx.HSet(key, []byte("1"), []byte("1"))
c.Assert(err, IsNil)

Expand Down Expand Up @@ -334,6 +362,13 @@ func (s *testTxStructureSuite) TestHash(c *C) {
c.Assert(err, IsNil)
c.Assert(value, DeepEquals, []byte("2"))

tx1 := structure.NewStructure(txn, nil, []byte{0x01})
_, err = tx1.HInc(key, []byte("1"), 1)
c.Assert(err, NotNil)

err = tx1.HDel(key, []byte("1"))
c.Assert(err, NotNil)

err = txn.Commit(context.Background())
c.Assert(err, IsNil)

Expand Down

0 comments on commit e9482cf

Please sign in to comment.