Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: migrate test framework to testify #5193

Merged
merged 4 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions pkg/assertutil/assertutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@ type Checker struct {
}

// NewChecker creates Checker with FailNow function.
func NewChecker(failNow func()) *Checker {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this arg?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we remove all pingcap/check dependencies, we can change it back.

return &Checker{
FailNow: failNow,
}
}

func (c *Checker) failNow() {
c.FailNow()
func NewChecker() *Checker {
return &Checker{}
}

// AssertNil calls the injected IsNil assertion.
func (c *Checker) AssertNil(obtained interface{}) {
if c.IsNil == nil {
c.failNow()
c.FailNow()
return
}
c.IsNil(obtained)
Expand Down
5 changes: 3 additions & 2 deletions pkg/assertutil/assertutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func TestNilFail(t *testing.T) {
t.Parallel()
re := require.New(t)
var failErr error
checker := NewChecker(func() {
checker := NewChecker()
checker.FailNow = func() {
failErr = errors.New("called assert func not exist")
})
}
re.Nil(checker.IsNil)
checker.AssertNil(nil)
re.NotNil(failErr)
Expand Down
5 changes: 4 additions & 1 deletion server/api/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import (
var _ = Suite(&testVersionSuite{})

func checkerWithNilAssert(c *C) *assertutil.Checker {
checker := assertutil.NewChecker(c.FailNow)
checker := assertutil.NewChecker()
checker.FailNow = func() {
c.FailNow()
}
checker.IsNil = func(obtained interface{}) {
c.Assert(obtained, IsNil)
}
Expand Down
26 changes: 11 additions & 15 deletions server/join/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,28 @@ package join
import (
"testing"

. "github.com/pingcap/check"
"github.com/stretchr/testify/require"
"github.com/tikv/pd/pkg/assertutil"
"github.com/tikv/pd/pkg/testutil"
"github.com/tikv/pd/server"
)

func TestJoin(t *testing.T) {
TestingT(t)
}

var _ = Suite(&testJoinServerSuite{})

type testJoinServerSuite struct{}

func checkerWithNilAssert(c *C) *assertutil.Checker {
checker := assertutil.NewChecker(c.FailNow)
func checkerWithNilAssert(re *require.Assertions) *assertutil.Checker {
checker := assertutil.NewChecker()
checker.FailNow = func() {
re.FailNow("")
}
checker.IsNil = func(obtained interface{}) {
c.Assert(obtained, IsNil)
re.Nil(obtained)
}
return checker
}

// A PD joins itself.
func (s *testJoinServerSuite) TestPDJoinsItself(c *C) {
cfg := server.NewTestSingleConfig(checkerWithNilAssert(c))
func TestPDJoinsItself(t *testing.T) {
re := require.New(t)
cfg := server.NewTestSingleConfig(checkerWithNilAssert(re))
defer testutil.CleanServer(cfg.DataDir)
cfg.Join = cfg.AdvertiseClientUrls
c.Assert(PrepareJoinCluster(cfg), NotNil)
re.Error(PrepareJoinCluster(cfg))
}
Loading