Skip to content

Commit

Permalink
add more unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
puritys committed Nov 14, 2015
1 parent 45af6ff commit 0061b3a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/js/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,7 @@ exports.mysql_close = mysql_close;
exports.mysql_create_db = mysql_create_db;
exports.mysql_insert_id = mysql_insert_id;

if (typeof(global.UNIT_TEST) != "undefined" && true === global.UNIT_TEST) {
exports.mysql_login = mysql_login;
}

10 changes: 9 additions & 1 deletion tests/mock/socket.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

var cmd = "";
if (!global['mockSocket']) {
global.mockSocket = [];
}
Expand Down Expand Up @@ -34,6 +34,7 @@ exports.fsockopen = function () {
};

exports.sendcmd = function (msg) {
cmd = msg;
return msg;
};

Expand All @@ -44,3 +45,10 @@ exports.recv = function () {
exports.fread = function () {
return recv2();
};

exports.getcmd = function () {
return cmd;
};



29 changes: 28 additions & 1 deletion tests/mysql/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ var packetReader = require('./../../src/js/mysql/packetReader.js');

var serverInfo = {
"session": "0000",
"protocol41": true
"protocol41": true,
"authPluginDataPart1": "xxx",
"authPluginDataPart2": "xxx"
};

function setResponseBuffer(data) {//{{{
Expand Down Expand Up @@ -186,3 +188,28 @@ describe('Mysql: method mysql_query', function() {//{{{

});

describe("MySql: method mysql_close", function () {
it("Normal", function () {
var ret = php.mysql_close({"connectId": 1, "session": "12"});
var cmd = socket.getcmd();
assert.equal(5, cmd.readIntLE(0, 1));
assert.equal(12, cmd.readIntLE(4, 1));
assert.equal(1, cmd.readIntLE(5, 1));
});

});

describe("MySql: method mysql_login", function () {
it("Normal", function () {
php.mysql_login(serverInfo, "user", "pswd", "db");
var cmd = socket.getcmd();
assert.equal(61, cmd.readIntLE(0, 1));
assert.equal(33, cmd.readIntLE(12, 1));

});

});




0 comments on commit 0061b3a

Please sign in to comment.