@@ -10,6 +10,7 @@ package mysql
10
10
11
11
import (
12
12
"context"
13
+ "io"
13
14
"net"
14
15
"testing"
15
16
)
@@ -52,37 +53,43 @@ func TestReadPacketSingleByte(t *testing.T) {
52
53
}
53
54
}
54
55
55
- // func TestReadPacketWrongSequenceID(t *testing.T) {
56
- // for _, testCase := range []struct {
57
- // ClientSequenceID byte
58
- // ServerSequenceID byte
59
- // ExpectedErr error
60
- // }{
61
- // {
62
- // ClientSequenceID: 1,
63
- // ServerSequenceID: 0,
64
- // ExpectedErr: ErrPktSync,
65
- // },
66
- // {
67
- // ClientSequenceID: 0,
68
- // ServerSequenceID: 0x42,
69
- // ExpectedErr: ErrPktSyncMul,
70
- // },
71
- // } {
72
- // conn, mc := newRWMockConn(testCase.ClientSequenceID)
73
-
74
- // conn.data = []byte{0x01, 0x00, 0x00, testCase.ServerSequenceID, 0xff}
75
- // _, err := mc.readPacket()
76
- // if err != testCase.ExpectedErr {
77
- // t.Errorf("expected %v, got %v", testCase.ExpectedErr, err)
78
- // }
79
-
80
- // // connection should not be returned to the pool in this state
81
- // if mc.IsValid() {
82
- // t.Errorf("expected IsValid() to be false")
83
- // }
84
- // }
85
- // }
56
+ func TestReadPacketWrongSequenceID (t * testing.T ) {
57
+ for _ , testCase := range []struct {
58
+ ClientSequenceID byte
59
+ ServerSequenceID byte
60
+ ExpectedErr error
61
+ }{
62
+ {
63
+ ClientSequenceID : 1 ,
64
+ ServerSequenceID : 0 ,
65
+ ExpectedErr : ErrPktSync ,
66
+ },
67
+ {
68
+ ClientSequenceID : 0 ,
69
+ ServerSequenceID : 0x42 ,
70
+ ExpectedErr : ErrPktSyncMul ,
71
+ },
72
+ } {
73
+ testCase := testCase
74
+
75
+ conn , mc := newRWMockConn (t , testCase .ClientSequenceID )
76
+ go func () {
77
+ io .Copy (io .Discard , conn )
78
+ }()
79
+ go func () {
80
+ conn .Write ([]byte {0x01 , 0x00 , 0x00 , testCase .ServerSequenceID , 0xff })
81
+ }()
82
+ _ , err := mc .readPacket (context .Background ())
83
+ if err != testCase .ExpectedErr {
84
+ t .Errorf (`expected "%v", got "%v"` , testCase .ExpectedErr , err )
85
+ }
86
+
87
+ // connection should not be returned to the pool in this state
88
+ if mc .IsValid () {
89
+ t .Errorf ("expected IsValid() to be false" )
90
+ }
91
+ }
92
+ }
86
93
87
94
// func TestReadPacketSplit(t *testing.T) {
88
95
// conn := new(mockConn)
0 commit comments