test-change-user.js 938 B

12345678910111213141516171819202122232425262728293031323334353637
  1. var common = require('../../common');
  2. var connection = common.createConnection();
  3. var assert = require('assert');
  4. if (common.isTravis()) {
  5. return console.log('skipping - travis mysql does not support this test');
  6. }
  7. connection.query('CREATE DATABASE ' + common.testDatabase, function(err) {
  8. if (err && err.code !== 'ER_DB_CREATE_EXISTS') throw err;
  9. });
  10. var initialDb;
  11. connection.query('select database() as db', function(err, results) {
  12. if (err) throw err;
  13. initialDb = results[0].db;
  14. assert.equal(connection.config.database, null);
  15. });
  16. connection.changeUser({database: common.testDatabase});
  17. var finalDb;
  18. connection.query('select database() as db', function(err, results){
  19. if (err) throw err;
  20. finalDb = results[0].db;
  21. assert.equal(connection.config.database, finalDb);
  22. });
  23. connection.end();
  24. process.on('exit', function() {
  25. assert.equal(initialDb, null);
  26. assert.equal(finalDb, common.testDatabase);
  27. });