Skip to content

Commit 016b294

Browse files
committed
tests: add ok helper method for unit tests
1 parent b6ad520 commit 016b294

7 files changed

+15
-19
lines changed

test/FakeServer.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,14 @@ FakeConnection.prototype.handshake = function(options) {
100100
this._sendPacket(this._handshakeInitializationPacket);
101101
};
102102

103+
FakeConnection.prototype.ok = function ok() {
104+
this._sendPacket(new Packets.OkPacket());
105+
this._parser.resetPacketNumber();
106+
};
107+
103108
FakeConnection.prototype._sendAuthResponse = function _sendAuthResponse(got, expected) {
104109
if (expected.toString('hex') === got.toString('hex')) {
105-
this._sendPacket(new Packets.OkPacket());
110+
this.ok();
106111
} else {
107112
this.deny('expected ' + expected.toString('hex') + ' got ' + got.toString('hex'));
108113
}
@@ -280,8 +285,7 @@ FakeConnection.prototype._parsePacket = function() {
280285
this.user = (packet.user || null);
281286

282287
if (!this.emit('clientAuthentication', packet)) {
283-
this._sendPacket(new Packets.OkPacket());
284-
this._parser.resetPacketNumber();
288+
this.ok();
285289
}
286290
break;
287291
case Packets.SSLRequestPacket:
@@ -294,8 +298,7 @@ FakeConnection.prototype._parsePacket = function() {
294298
break;
295299
case Packets.ComPingPacket:
296300
if (!this.emit('ping', packet)) {
297-
this._sendPacket(new Packets.OkPacket());
298-
this._parser.resetPacketNumber();
301+
this.ok();
299302
}
300303
break;
301304
case Packets.ComChangeUserPacket:
@@ -311,8 +314,7 @@ FakeConnection.prototype._parsePacket = function() {
311314
break;
312315
}
313316

314-
this._sendPacket(new Packets.OkPacket());
315-
this._parser.resetPacketNumber();
317+
this.ok();
316318
}
317319
break;
318320
case Packets.ComQuitPacket:

test/unit/connection/test-exception-safety.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ server.on('connection', function (conn) {
7676
this.error('Parse error', common.Errors.ER_PARSE_ERROR);
7777
break;
7878
case 'USE test':
79-
this._sendPacket(new common.Packets.OkPacket());
80-
this._parser.resetPacketNumber();
79+
this.ok();
8180
break;
8281
default:
8382
this._handleQueryPacket(packet);

test/unit/connection/test-packet-out-of-order.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ server.listen(common.fakeServerPort, function(err) {
1010
connection.connect(function(err) {
1111
assert.ifError(err);
1212

13-
serverConn._sendPacket(new common.Packets.OkPacket());
14-
serverConn._parser.resetPacketNumber();
13+
serverConn.ok();
1514

1615
connection.end(function(err) {
1716
assert.ok(err);

test/unit/connection/test-quit-ok-packet.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ server.listen(common.fakeServerPort, function (err) {
1616
server.on('connection', function (conn) {
1717
conn.handshake();
1818
conn.on('quit', function () {
19-
conn._sendPacket(new common.Packets.OkPacket());
20-
conn._parser.resetPacketNumber();
19+
conn.ok();
2120
});
2221
});

test/unit/pool/test-acquire-timeout-existing.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ server.on('connection', function(incomingConnection) {
4848
});
4949
incomingConnection.on('ping', function() {
5050
if (!fail) {
51-
this._sendPacket(new common.Packets.OkPacket());
52-
this._parser.resetPacketNumber();
51+
this.ok();
5352
}
5453

5554
fail = false;

test/unit/pool/test-connection-bad.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ server.on('connection', function(incomingConnection) {
4949
if (fail) {
5050
setTimeout(this.destroy.bind(this), 100);
5151
} else {
52-
this._sendPacket(new common.Packets.OkPacket());
53-
this._parser.resetPacketNumber();
52+
this.ok();
5453
}
5554

5655
fail = false;

test/unit/pool/test-end-ping.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ server.on('connection', function (conn) {
3333
conn.handshake();
3434
conn.on('ping', function () {
3535
setTimeout(function () {
36-
conn._sendPacket(new common.Packets.OkPacket());
37-
conn._parser.resetPacketNumber();
36+
conn.ok();
3837
}, 100);
3938
});
4039
});

0 commit comments

Comments
 (0)