Skip to content

Commit 6d945fb

Browse files
committed
change more files
Signed-off-by: lance6716 <lance6716@gmail.com>
1 parent d0ccb19 commit 6d945fb

12 files changed

+181
-201
lines changed

Diff for: client/auth_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ func TestConnGenAttributes(t *testing.T) {
3131

3232
for k, v := range c.attributes {
3333
fixt := append(mysql.PutLengthEncodedString([]byte(k)), mysql.PutLengthEncodedString([]byte(v))...)
34-
require.Contains(t, data, fixt)
34+
require.Subset(t, data, fixt)
3535
}
3636
}

Diff for: mysql/position_test.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package mysql
22

33
import (
4-
"github.com/pingcap/check"
5-
)
6-
7-
type positionCompareSuite struct {
8-
}
4+
"testing"
95

10-
var _ = check.Suite(&positionCompareSuite{})
6+
"github.com/stretchr/testify/require"
7+
)
118

12-
func (t *positionCompareSuite) TestPosCompare(c *check.C) {
9+
func TestPosCompare(t *testing.T) {
1310
ascendingPositions := []Position{
1411
{
1512
"",
@@ -42,10 +39,10 @@ func (t *positionCompareSuite) TestPosCompare(c *check.C) {
4239
}
4340

4441
for i := 1; i < len(ascendingPositions); i++ {
45-
c.Assert(ascendingPositions[i-1].Compare(ascendingPositions[i]), check.Equals, -1)
42+
require.Equal(t, -1, ascendingPositions[i-1].Compare(ascendingPositions[i]))
4643
}
4744

4845
for _, p := range ascendingPositions {
49-
c.Assert(p.Compare(p), check.Equals, 0)
46+
require.Equal(t, 0, p.Compare(p))
5047
}
5148
}

Diff for: mysql/util_test.go

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package mysql
22

33
import (
4-
"github.com/pingcap/check"
5-
)
6-
7-
type utilTestSuite struct {
8-
}
4+
"testing"
95

10-
var _ = check.Suite(&utilTestSuite{})
6+
"github.com/stretchr/testify/require"
7+
)
118

12-
func (s *utilTestSuite) TestCompareServerVersions(c *check.C) {
9+
func TestCompareServerVersions(t *testing.T) {
1310
tests := []struct {
1411
A string
1512
B string
@@ -21,10 +18,8 @@ func (s *utilTestSuite) TestCompareServerVersions(c *check.C) {
2118
}
2219

2320
for _, test := range tests {
24-
comment := check.Commentf("%q vs. %q", test.A, test.B)
25-
2621
got, err := CompareServerVersions(test.A, test.B)
27-
c.Assert(err, check.IsNil, comment)
28-
c.Assert(got, check.Equals, test.Expect, comment)
22+
require.NoError(t, err)
23+
require.Equal(t, test.Expect, got)
2924
}
3025
}

Diff for: replication/replication_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func (t *testSyncerSuite) testPositionSync() {
316316
require.NoError(t.T(), err)
317317

318318
// List of replicas must not be empty
319-
require.Len(t.T(), r.Values, 0)
319+
require.Greater(t.T(), len(r.Values), 0)
320320

321321
// Slave_UUID is empty for mysql 8.0.28+ (8.0.32 still broken)
322322
if eq, err := t.c.CompareServerVersion("8.0.28"); (err == nil) && (eq < 0) {

Diff for: replication/time_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ func TestTimeStringLocation(tt *testing.T) {
5454
nil,
5555
}
5656

57-
require.Equal(tt, "2018-07-30 15:00:00", t.String())
57+
require.Equal(tt, "2018-07-30 10:00:00", t.String())
5858

5959
t = fracTime{
6060
time.Date(2018, time.Month(7), 30, 10, 0, 0, 0, time.FixedZone("EST", -5*3600)),
6161
0,
6262
time.UTC,
6363
}
64-
require.Equal(tt, "2018-07-30 10:00:00", t.String())
64+
require.Equal(tt, "2018-07-30 15:00:00", t.String())
6565
}

Diff for: schema/schema_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ func (s *schemaTestSuite) TestSchema() {
9292
require.Nil(s.T(), ta.GetPKColumn(2))
9393
require.Nil(s.T(), ta.GetPKColumn(3))
9494
require.Len(s.T(), ta.Indexes[0].Columns, 2)
95-
require.Equal(s.T(), "PRIMARY", ta.Columns[0].Name)
96-
require.Equal(s.T(), "name_idx", ta.Columns[2].Name)
95+
require.Equal(s.T(), "PRIMARY", ta.Indexes[0].Name)
96+
require.Equal(s.T(), "name_idx", ta.Indexes[2].Name)
9797
require.Equal(s.T(), TYPE_STRING, ta.Columns[3].Type)
9898
require.Equal(s.T(), uint(256), ta.Columns[3].MaxSize)
9999
require.Equal(s.T(), uint(0), ta.Columns[3].FixedSize)

Diff for: server/caching_sha2_cache_test.go

+24-26
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
"time"
1111

1212
_ "github.com/go-sql-driver/mysql"
13-
. "github.com/pingcap/check"
1413
"github.com/pingcap/errors"
1514
"github.com/siddontang/go-log/log"
15+
"github.com/stretchr/testify/require"
16+
"github.com/stretchr/testify/suite"
1617

1718
"github.com/go-mysql-org/go-mysql/mysql"
1819
"github.com/go-mysql-org/go-mysql/test_util"
@@ -32,13 +33,11 @@ func TestCachingSha2Cache(t *testing.T) {
3233
cacheServer := NewServer("8.0.12", mysql.DEFAULT_COLLATION_ID, mysql.AUTH_CACHING_SHA2_PASSWORD, test_keys.PubPem, tlsConf)
3334

3435
// no TLS
35-
Suite(&cacheTestSuite{
36+
suite.Run(t, &cacheTestSuite{
3637
server: cacheServer,
3738
credProvider: remoteProvider,
3839
tlsPara: "false",
3940
})
40-
41-
TestingT(t)
4241
}
4342

4443
func TestCachingSha2CacheTLS(t *testing.T) {
@@ -49,13 +48,11 @@ func TestCachingSha2CacheTLS(t *testing.T) {
4948
cacheServer := NewServer("8.0.12", mysql.DEFAULT_COLLATION_ID, mysql.AUTH_CACHING_SHA2_PASSWORD, test_keys.PubPem, tlsConf)
5049

5150
// TLS
52-
Suite(&cacheTestSuite{
51+
suite.Run(t, &cacheTestSuite{
5352
server: cacheServer,
5453
credProvider: remoteProvider,
5554
tlsPara: "skip-verify",
5655
})
57-
58-
TestingT(t)
5956
}
6057

6158
type RemoteThrottleProvider struct {
@@ -69,6 +66,7 @@ func (m *RemoteThrottleProvider) GetCredential(username string) (password string
6966
}
7067

7168
type cacheTestSuite struct {
69+
suite.Suite
7270
server *Server
7371
serverAddr string
7472
credProvider CredentialProvider
@@ -79,40 +77,40 @@ type cacheTestSuite struct {
7977
l net.Listener
8078
}
8179

82-
func (s *cacheTestSuite) SetupSuite(c *C) {
80+
func (s *cacheTestSuite) SetupSuite() {
8381
s.serverAddr = fmt.Sprintf("%s:%s", *test_util.MysqlFakeHost, *test_util.MysqlFakePort)
8482

8583
var err error
8684

8785
s.l, err = net.Listen("tcp", s.serverAddr)
88-
c.Assert(err, IsNil)
86+
require.NoError(s.T(), err)
8987

90-
go s.onAccept(c)
88+
go s.onAccept()
9189

9290
time.Sleep(30 * time.Millisecond)
9391
}
9492

95-
func (s *cacheTestSuite) TearDownSuite(c *C) {
93+
func (s *cacheTestSuite) TearDownSuite() {
9694
if s.l != nil {
9795
s.l.Close()
9896
}
9997
}
10098

101-
func (s *cacheTestSuite) onAccept(c *C) {
99+
func (s *cacheTestSuite) onAccept() {
102100
for {
103101
conn, err := s.l.Accept()
104102
if err != nil {
105103
return
106104
}
107105

108-
go s.onConn(conn, c)
106+
go s.onConn(conn)
109107
}
110108
}
111109

112-
func (s *cacheTestSuite) onConn(conn net.Conn, c *C) {
110+
func (s *cacheTestSuite) onConn(conn net.Conn) {
113111
//co, err := NewConn(conn, *testUser, *testPassword, &testHandler{s})
114112
co, err := NewCustomizedConn(conn, s.server, s.credProvider, &testCacheHandler{s})
115-
c.Assert(err, IsNil)
113+
require.NoError(s.T(), err)
116114
for {
117115
err = co.HandleCommand()
118116
if err != nil {
@@ -121,30 +119,30 @@ func (s *cacheTestSuite) onConn(conn net.Conn, c *C) {
121119
}
122120
}
123121

124-
func (s *cacheTestSuite) runSelect(c *C) {
122+
func (s *cacheTestSuite) runSelect() {
125123
var a int64
126124
var b string
127125

128126
err := s.db.QueryRow("SELECT a, b FROM tbl WHERE id=1").Scan(&a, &b)
129-
c.Assert(err, IsNil)
130-
c.Assert(a, Equals, int64(1))
131-
c.Assert(b, Equals, "hello world")
127+
require.NoError(s.T(), err)
128+
require.Equal(s.T(), int64(1), a)
129+
require.Equal(s.T(), "hello world", b)
132130
}
133131

134-
func (s *cacheTestSuite) TestCache(c *C) {
132+
func (s *cacheTestSuite) TestCache() {
135133
// first connection
136134
t1 := time.Now()
137135
var err error
138136
s.db, err = sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?tls=%s", *testUser, *testPassword, s.serverAddr, *testDB, s.tlsPara))
139-
c.Assert(err, IsNil)
137+
require.NoError(s.T(), err)
140138
s.db.SetMaxIdleConns(4)
141-
s.runSelect(c)
139+
s.runSelect()
142140
t2 := time.Now()
143141

144142
d1 := int(t2.Sub(t1).Nanoseconds() / 1e6)
145143
//log.Debugf("first connection took %d milliseconds", d1)
146144

147-
c.Assert(d1, GreaterEqual, delay)
145+
require.GreaterOrEqual(s.T(), d1, delay)
148146

149147
if s.db != nil {
150148
s.db.Close()
@@ -153,15 +151,15 @@ func (s *cacheTestSuite) TestCache(c *C) {
153151
// second connection
154152
t3 := time.Now()
155153
s.db, err = sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?tls=%s", *testUser, *testPassword, s.serverAddr, *testDB, s.tlsPara))
156-
c.Assert(err, IsNil)
154+
require.NoError(s.T(), err)
157155
s.db.SetMaxIdleConns(4)
158-
s.runSelect(c)
156+
s.runSelect()
159157
t4 := time.Now()
160158

161159
d2 := int(t4.Sub(t3).Nanoseconds() / 1e6)
162160
//log.Debugf("second connection took %d milliseconds", d2)
163161

164-
c.Assert(d2, Less, delay)
162+
require.Less(s.T(), d2, delay)
165163
if s.db != nil {
166164
s.db.Close()
167165
}

Diff for: server/conn_test.go

+19-22
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package server
22

33
import (
4+
"testing"
5+
46
"github.com/go-mysql-org/go-mysql/mysql"
5-
"github.com/pingcap/check"
7+
"github.com/stretchr/testify/require"
68
)
79

8-
type connTestSuite struct {
9-
}
10-
11-
var _ = check.Suite(&connTestSuite{})
12-
13-
func (t *connTestSuite) TestStatus(c *check.C) {
10+
func TestStatus(t *testing.T) {
1411
conn := Conn{}
1512

1613
flags := []uint16{
@@ -29,35 +26,35 @@ func (t *connTestSuite) TestStatus(c *check.C) {
2926
}
3027

3128
for _, f := range flags {
32-
c.Assert(conn.HasStatus(f), check.IsFalse)
29+
require.False(t, conn.HasStatus(f))
3330
conn.SetStatus(f)
34-
c.Assert(conn.HasStatus(f), check.IsTrue)
31+
require.True(t, conn.HasStatus(f))
3532
conn.UnsetStatus(f)
36-
c.Assert(conn.HasStatus(f), check.IsFalse)
33+
require.False(t, conn.HasStatus(f))
3734
}
3835

3936
// check special flag setters
4037
// IsAutoCommit
41-
c.Assert(conn.IsAutoCommit(), check.IsFalse)
38+
require.False(t, conn.IsAutoCommit())
4239
conn.SetStatus(mysql.SERVER_STATUS_AUTOCOMMIT)
43-
c.Assert(conn.IsAutoCommit(), check.IsTrue)
40+
require.True(t, conn.IsAutoCommit())
4441
conn.UnsetStatus(mysql.SERVER_STATUS_AUTOCOMMIT)
4542

4643
// IsInTransaction
47-
c.Assert(conn.IsInTransaction(), check.IsFalse)
44+
require.False(t, conn.IsInTransaction())
4845
conn.SetStatus(mysql.SERVER_STATUS_IN_TRANS)
49-
c.Assert(conn.IsInTransaction(), check.IsTrue)
46+
require.True(t, conn.IsInTransaction())
5047
conn.UnsetStatus(mysql.SERVER_STATUS_IN_TRANS)
5148

5249
// SetInTransaction & ClearInTransaction
53-
c.Assert(conn.HasStatus(mysql.SERVER_STATUS_IN_TRANS), check.IsFalse)
50+
require.False(t, conn.HasStatus(mysql.SERVER_STATUS_IN_TRANS))
5451
conn.SetInTransaction()
55-
c.Assert(conn.HasStatus(mysql.SERVER_STATUS_IN_TRANS), check.IsTrue)
52+
require.True(t, conn.HasStatus(mysql.SERVER_STATUS_IN_TRANS))
5653
conn.ClearInTransaction()
57-
c.Assert(conn.HasStatus(mysql.SERVER_STATUS_IN_TRANS), check.IsFalse)
54+
require.False(t, conn.HasStatus(mysql.SERVER_STATUS_IN_TRANS))
5855
}
5956

60-
func (t *connTestSuite) TestCapability(c *check.C) {
57+
func TestCapability(t *testing.T) {
6158
conn := Conn{}
6259

6360
caps := []uint32{
@@ -86,11 +83,11 @@ func (t *connTestSuite) TestCapability(c *check.C) {
8683
}
8784

8885
for _, capI := range caps {
89-
c.Assert(conn.HasCapability(capI), check.IsFalse)
86+
require.False(t, conn.HasCapability(capI))
9087
conn.SetCapability(capI)
91-
c.Assert(conn.HasCapability(capI), check.IsTrue)
92-
c.Assert(conn.Capability()&capI > 0, check.IsTrue)
88+
require.True(t, conn.HasCapability(capI))
89+
require.True(t, conn.Capability()&capI > 0)
9390
conn.UnsetCapability(capI)
94-
c.Assert(conn.HasCapability(capI), check.IsFalse)
91+
require.False(t, conn.HasCapability(capI))
9592
}
9693
}

Diff for: server/handshake_resp_test.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/go-mysql-org/go-mysql/mocks"
88
"github.com/go-mysql-org/go-mysql/mysql"
99
"github.com/stretchr/testify/mock"
10+
"github.com/stretchr/testify/require"
1011
)
1112

1213
func TestReadAuthData(t *testing.T) {
@@ -18,18 +19,12 @@ func TestReadAuthData(t *testing.T) {
1819

1920
// test out of range index returns 'bad handshake' error
2021
_, _, _, err := c.readAuthData(data, len(data))
21-
if err == nil || err.Error() != "ERROR 1043 (08S01): Bad handshake" {
22-
t.Fatal("expected error, got nil")
23-
}
22+
require.ErrorContains(t, err, "ERROR 1043 (08S01): Bad handshake")
2423

2524
// test good index position reads auth data
2625
_, _, readBytes, err := c.readAuthData(data, len(data)-1)
27-
if err != nil {
28-
t.Fatalf("expected nil error, got %v", err)
29-
}
30-
if readBytes != len(data)-1 {
31-
t.Fatalf("expected %d read bytes, got %d", len(data)-1, readBytes)
32-
}
26+
require.NoError(t, err)
27+
require.Equal(t, len(data)-1, readBytes)
3328
}
3429

3530
func TestDecodeFirstPart(t *testing.T) {

0 commit comments

Comments
 (0)