diff --git a/errno/infoschema_test.go b/errno/infoschema_test.go index 1a8d0f0c3984c..17d217b2e6c80 100644 --- a/errno/infoschema_test.go +++ b/errno/infoschema_test.go @@ -16,18 +16,11 @@ package errno import ( "testing" - . "github.com/pingcap/check" + "github.com/stretchr/testify/assert" ) -func TestT(t *testing.T) { - TestingT(t) -} - -var _ = Suite(&testErrno{}) - -type testErrno struct{} - -func (s *testErrno) TestCopySafety(c *C) { +func TestCopySafety(t *testing.T) { + t.Parallel() IncrementError(123, "user", "host") IncrementError(321, "user2", "host2") @@ -48,42 +41,42 @@ func (s *testErrno) TestCopySafety(c *C) { IncrementWarning(333, "c", "d") // global stats - c.Assert(stats.global[123].ErrorCount, Equals, 3) - c.Assert(globalCopy[123].ErrorCount, Equals, 1) + assert.Equal(t, 3, stats.global[123].ErrorCount) + assert.Equal(t, 1, globalCopy[123].ErrorCount) // user stats - c.Assert(len(stats.users), Equals, 6) - c.Assert(len(userCopy), Equals, 3) - c.Assert(stats.users["user"][123].ErrorCount, Equals, 2) - c.Assert(stats.users["user"][123].WarningCount, Equals, 2) - c.Assert(userCopy["user"][123].ErrorCount, Equals, 1) - c.Assert(userCopy["user"][123].WarningCount, Equals, 1) + assert.Len(t, stats.users, 6) + assert.Len(t, userCopy, 3) + assert.Equal(t, 2, stats.users["user"][123].ErrorCount) + assert.Equal(t, 2, stats.users["user"][123].WarningCount) + assert.Equal(t, 1, userCopy["user"][123].ErrorCount) + assert.Equal(t, 1, userCopy["user"][123].WarningCount) // ensure there is no user3 in userCopy _, ok := userCopy["user3"] - c.Assert(ok, IsFalse) + assert.False(t, ok) _, ok = stats.users["user3"] - c.Assert(ok, IsTrue) + assert.True(t, ok) _, ok = userCopy["a"] - c.Assert(ok, IsFalse) + assert.False(t, ok) _, ok = stats.users["a"] - c.Assert(ok, IsTrue) + assert.True(t, ok) // host stats - c.Assert(len(stats.hosts), Equals, 5) - c.Assert(len(hostCopy), Equals, 3) + assert.Len(t, stats.hosts, 5) + assert.Len(t, hostCopy, 3) + IncrementError(123, "user3", "newhost") - c.Assert(len(stats.hosts), Equals, 6) - c.Assert(len(hostCopy), Equals, 3) + assert.Len(t, stats.hosts, 6) + assert.Len(t, hostCopy, 3) // ensure there is no newhost in hostCopy _, ok = hostCopy["newhost"] - c.Assert(ok, IsFalse) + assert.False(t, ok) _, ok = stats.hosts["newhost"] - c.Assert(ok, IsTrue) + assert.True(t, ok) _, ok = hostCopy["b"] - c.Assert(ok, IsFalse) + assert.False(t, ok) _, ok = stats.hosts["b"] - c.Assert(ok, IsTrue) - + assert.True(t, ok) } diff --git a/errno/main_test.go b/errno/main_test.go new file mode 100644 index 0000000000000..f8becfac4d3f0 --- /dev/null +++ b/errno/main_test.go @@ -0,0 +1,26 @@ +// Copyright 2021 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package errno + +import ( + "os" + "testing" + + "github.com/pingcap/tidb/util/testbridge" +) + +func TestMain(m *testing.M) { + testbridge.WorkaroundGoCheckFlags() + os.Exit(m.Run()) +} diff --git a/go.mod b/go.mod index d2a46a0a473e7..20ac7530e7037 100644 --- a/go.mod +++ b/go.mod @@ -54,6 +54,7 @@ require ( github.com/rivo/uniseg v0.2.0 // indirect github.com/shirou/gopsutil v3.21.2+incompatible github.com/soheilhy/cmux v0.1.4 + github.com/stretchr/testify v1.7.0 github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 github.com/tikv/client-go/v2 v2.0.0-alpha.0.20210709052506-aadf3cf62721 github.com/tikv/pd v1.1.0-beta.0.20210323121136-78679e5e209d diff --git a/util/testbridge/bridge.go b/util/testbridge/bridge.go new file mode 100644 index 0000000000000..e792bfbb879ac --- /dev/null +++ b/util/testbridge/bridge.go @@ -0,0 +1,34 @@ +// Copyright 2021 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build !codes + +package testbridge + +import ( + "flag" +) + +// WorkaroundGoCheckFlags registers flags of go-check for pkg does not import go-check +// to workaround the go-check flags passed in Makefile. +// +// TODO: Remove this function when the migration from go-check to testify[1] is done. +// [1] https://github.com/pingcap/tidb/issues/26022 +func WorkaroundGoCheckFlags() { + if flag.Lookup("check.timeout") == nil { + _ = flag.Duration("check.timeout", 0, "WorkaroundGoCheckFlags: check.timeout") + } + if flag.Lookup("check.p") == nil { + _ = flag.Bool("check.p", false, "WorkaroundGoCheckFlags: check.p") + } +}