From 7403c63e323e220acb25409518ebe498391b93f9 Mon Sep 17 00:00:00 2001 From: disksing Date: Mon, 21 Jun 2021 23:53:10 +0800 Subject: [PATCH] util: replace pingcap/check with testify (#103) Signed-off-by: disksing --- go.mod | 1 + go.sum | 3 +++ integration_tests/go.mod | 1 + integration_tests/go.sum | 3 +++ integration_tests/prewrite_test.go | 36 +++++++++++++----------------- util/misc_test.go | 24 ++++++++------------ util/rate_limit_test.go | 19 +++++++++------- 7 files changed, 44 insertions(+), 43 deletions(-) diff --git a/go.mod b/go.mod index 9a55622a..b15669dd 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( github.com/prometheus/client_model v0.2.0 github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/sirupsen/logrus v1.6.0 // indirect + github.com/stretchr/testify v1.7.0 github.com/tikv/pd v1.1.0-beta.0.20210323121136-78679e5e209d github.com/twmb/murmur3 v1.1.3 go.etcd.io/etcd v0.5.0-alpha.5.0.20200824191128-ae9734ed278b diff --git a/go.sum b/go.sum index 703fe178..e0cf1cd8 100644 --- a/go.sum +++ b/go.sum @@ -210,9 +210,11 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= @@ -597,6 +599,7 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c/go.mod h1:3HH7i1SgMqlzxCcBmUHW657sD4Kvv9sC3HpL3YukzwA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/integration_tests/go.mod b/integration_tests/go.mod index feeb57b4..eb835228 100644 --- a/integration_tests/go.mod +++ b/integration_tests/go.mod @@ -9,6 +9,7 @@ require ( github.com/pingcap/kvproto v0.0.0-20210611081648-a215b4e61d2f github.com/pingcap/parser v0.0.0-20210618053735-57843e8185c4 github.com/pingcap/tidb v1.1.0-beta.0.20210616023036-9461f5ba55b1 + github.com/stretchr/testify v1.7.0 github.com/tikv/client-go/v2 v2.0.0 github.com/tikv/pd v1.1.0-beta.0.20210323121136-78679e5e209d go.uber.org/zap v1.17.0 diff --git a/integration_tests/go.sum b/integration_tests/go.sum index 56eb7414..b6466912 100644 --- a/integration_tests/go.sum +++ b/integration_tests/go.sum @@ -317,10 +317,12 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= @@ -877,6 +879,7 @@ gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c/go.mo gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/integration_tests/prewrite_test.go b/integration_tests/prewrite_test.go index 126bed5c..44f415e0 100644 --- a/integration_tests/prewrite_test.go +++ b/integration_tests/prewrite_test.go @@ -14,35 +14,31 @@ package tikv_test import ( - . "github.com/pingcap/check" + "testing" + "github.com/pingcap/kvproto/pkg/kvrpcpb" "github.com/pingcap/tidb/store/mockstore/unistore" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tikv/client-go/v2/tikv" ) -type testPrewriteSuite struct { - store *tikv.KVStore -} +func TestSetMinCommitTSInAsyncCommit(t *testing.T) { + require, assert := require.New(t), assert.New(t) -var _ = Suite(&testPrewriteSuite{}) - -func (s *testPrewriteSuite) SetUpTest(c *C) { client, pdClient, cluster, err := unistore.New("") - c.Assert(err, IsNil) + require.Nil(err) unistore.BootstrapWithSingleStore(cluster) store, err := tikv.NewTestTiKVStore(client, pdClient, nil, nil, 0) - c.Assert(err, IsNil) - s.store = store -} + require.Nil(err) -func (s *testPrewriteSuite) TestSetMinCommitTSInAsyncCommit(c *C) { - t, err := s.store.Begin() - c.Assert(err, IsNil) - txn := tikv.TxnProbe{KVTxn: t} + tx, err := store.Begin() + require.Nil(err) + txn := tikv.TxnProbe{KVTxn: tx} err = txn.Set([]byte("k"), []byte("v")) - c.Assert(err, IsNil) + assert.Nil(err) committer, err := txn.NewCommitter(1) - c.Assert(err, IsNil) + assert.Nil(err) committer.SetUseAsyncCommit() buildRequest := func() *kvrpcpb.PrewriteRequest { @@ -52,16 +48,16 @@ func (s *testPrewriteSuite) TestSetMinCommitTSInAsyncCommit(c *C) { // no forUpdateTS req := buildRequest() - c.Assert(req.MinCommitTs, Equals, txn.StartTS()+1) + assert.Equal(req.MinCommitTs, txn.StartTS()+1) // forUpdateTS is set committer.SetForUpdateTS(txn.StartTS() + (5 << 18)) req = buildRequest() - c.Assert(req.MinCommitTs, Equals, committer.GetForUpdateTS()+1) + assert.Equal(req.MinCommitTs, committer.GetForUpdateTS()+1) // minCommitTS is set committer.SetMinCommitTS(txn.StartTS() + (10 << 18)) req = buildRequest() - c.Assert(req.MinCommitTs, Equals, committer.GetMinCommitTS()) + assert.Equal(req.MinCommitTs, committer.GetMinCommitTS()) } diff --git a/util/misc_test.go b/util/misc_test.go index 2f0eeb63..61fb178d 100644 --- a/util/misc_test.go +++ b/util/misc_test.go @@ -17,19 +17,13 @@ import ( "testing" "time" - . "github.com/pingcap/check" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -func TestT(t *testing.T) { - TestingT(t) -} +func TestCompatibleParseGCTime(t *testing.T) { + assert, require := assert.New(t), require.New(t) -var _ = Suite(&testMiscSuite{}) - -type testMiscSuite struct { -} - -func (s *testMiscSuite) TestCompatibleParseGCTime(c *C) { values := []string{ "20181218-19:53:37 +0800 CST", "20181218-19:53:37 +0800 MST", @@ -55,19 +49,19 @@ func (s *testMiscSuite) TestCompatibleParseGCTime(c *C) { expectedTimeFormatted := "20181218-19:53:37 +0800" beijing, err := time.LoadLocation("Asia/Shanghai") - c.Assert(err, IsNil) + require.Nil(err) for _, value := range values { t, err := CompatibleParseGCTime(value) - c.Assert(err, IsNil) - c.Assert(t.Equal(expectedTime), Equals, true) + assert.Nil(err) + assert.True(t.Equal(expectedTime)) formatted := t.In(beijing).Format(GCTimeFormat) - c.Assert(formatted, Equals, expectedTimeFormatted) + assert.Equal(formatted, expectedTimeFormatted) } for _, value := range invalidValues { _, err := CompatibleParseGCTime(value) - c.Assert(err, NotNil) + assert.NotNil(err) } } diff --git a/util/rate_limit_test.go b/util/rate_limit_test.go index 29f4a72b..d11ce836 100644 --- a/util/rate_limit_test.go +++ b/util/rate_limit_test.go @@ -14,30 +14,33 @@ package util import ( + "testing" "time" - . "github.com/pingcap/check" + "github.com/stretchr/testify/assert" ) -func (s *testMiscSuite) TestRateLimit(c *C) { +func TestRateLimit(t *testing.T) { + assert := assert.New(t) + done := make(chan struct{}, 1) rl := NewRateLimit(1) - c.Assert(rl.PutToken, PanicMatches, "put a redundant token") + assert.PanicsWithValue("put a redundant token", rl.PutToken) exit := rl.GetToken(done) - c.Assert(exit, Equals, false) + assert.False(exit) rl.PutToken() - c.Assert(rl.PutToken, PanicMatches, "put a redundant token") + assert.PanicsWithValue("put a redundant token", rl.PutToken) exit = rl.GetToken(done) - c.Assert(exit, Equals, false) + assert.False(exit) done <- struct{}{} exit = rl.GetToken(done) // blocked but exit - c.Assert(exit, Equals, true) + assert.True(exit) sig := make(chan int, 1) go func() { exit = rl.GetToken(done) // blocked - c.Assert(exit, Equals, false) + assert.False(exit) close(sig) }() time.Sleep(200 * time.Millisecond)