不要怂,就是干,撸起袖子干!

Commit 7a1286d1 by Sushant Committed by Jan Aagaard Meier

(tests) movings configuration tests to unit tests

1 parent 01d5f0f4
...@@ -61,78 +61,7 @@ describe(Support.getTestDialectTeaser('Configuration'), function() { ...@@ -61,78 +61,7 @@ describe(Support.getTestDialectTeaser('Configuration'), function() {
}); });
}); });
describe('Instantiation with a URL string', function() {
it('should accept username, password, host, port, and database', function() {
var sequelize = new Sequelize('mysql://user:pass@example.com:9821/dbname');
var config = sequelize.config;
var options = sequelize.options;
expect(options.dialect).to.equal('mysql');
expect(config.database).to.equal('dbname');
expect(config.host).to.equal('example.com');
expect(config.username).to.equal('user');
expect(config.password).to.equal('pass');
expect(config.port).to.equal('9821');
});
it('should work with no authentication options', function() {
var sequelize = new Sequelize('mysql://example.com:9821/dbname');
var config = sequelize.config;
expect(config.username).to.not.be.ok;
expect(config.password).to.be.null;
});
it('should work with no authentication options and passing additional options', function() {
var sequelize = new Sequelize('mysql://example.com:9821/dbname', {});
var config = sequelize.config;
expect(config.username).to.not.be.ok;
expect(config.password).to.be.null;
});
it('should use the default port when no other is specified', function() {
var sequelize = new Sequelize('dbname', 'root', 'pass', {
dialect: dialect
})
, config = sequelize.config
, port;
if (Support.dialectIsMySQL()) {
port = 3306;
} else if (dialect === 'postgres' || dialect === 'postgres-native') {
port = 5432;
} else {
// sqlite has no concept of ports when connecting
return;
}
expect(config.port).to.equal(port);
});
});
describe('Instantiation with arguments', function() { describe('Instantiation with arguments', function() {
it('should accept four parameters (database, username, password, options)', function() {
var sequelize = new Sequelize('dbname', 'root', 'pass', {
port: 999,
dialect: dialect,
dialectOptions: {
supportBigNumbers: true,
bigNumberStrings: true
}
});
var config = sequelize.config;
expect(config.database).to.equal('dbname');
expect(config.username).to.equal('root');
expect(config.password).to.equal('pass');
expect(config.port).to.equal(999);
expect(sequelize.options.dialect).to.equal(dialect);
expect(config.dialectOptions.supportBigNumbers).to.be.true;
expect(config.dialectOptions.bigNumberStrings).to.be.true;
});
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
it('should respect READONLY / READWRITE connection modes', function() { it('should respect READONLY / READWRITE connection modes', function() {
var p = path.join(__dirname, '../tmp', 'foo.sqlite'); var p = path.join(__dirname, '../tmp', 'foo.sqlite');
......
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/support')
, Sequelize = Support.Sequelize
, dialect = Support.getTestDialect();
describe('Sequelize', function() {
describe('dialect is required', function() {
it('throw error when no dialect is supplied', function() {
expect(function() {
new Sequelize('localhost', 'test', 'test');
}).to.throw(Error);
});
it('works when dialect explicitly supplied', function() {
expect(function() {
new Sequelize('localhost', 'test', 'test', {
dialect: 'mysql'
});
}).not.to.throw(Error);
});
});
describe('Instantiation with arguments', function() {
it('should accept four parameters (database, username, password, options)', function() {
var sequelize = new Sequelize('dbname', 'root', 'pass', {
port: 999,
dialect: dialect,
dialectOptions: {
supportBigNumbers: true,
bigNumberStrings: true
}
});
var config = sequelize.config;
expect(config.database).to.equal('dbname');
expect(config.username).to.equal('root');
expect(config.password).to.equal('pass');
expect(config.port).to.equal(999);
expect(sequelize.options.dialect).to.equal(dialect);
expect(config.dialectOptions.supportBigNumbers).to.be.true;
expect(config.dialectOptions.bigNumberStrings).to.be.true;
});
});
describe('Instantiation with a URL string', function() {
it('should accept username, password, host, port, and database', function() {
var sequelize = new Sequelize('mysql://user:pass@example.com:9821/dbname');
var config = sequelize.config;
var options = sequelize.options;
expect(options.dialect).to.equal('mysql');
expect(config.database).to.equal('dbname');
expect(config.host).to.equal('example.com');
expect(config.username).to.equal('user');
expect(config.password).to.equal('pass');
expect(config.port).to.equal('9821');
});
it('should work with no authentication options', function() {
var sequelize = new Sequelize('mysql://example.com:9821/dbname');
var config = sequelize.config;
expect(config.username).to.not.be.ok;
expect(config.password).to.be.null;
});
it('should work with no authentication options and passing additional options', function() {
var sequelize = new Sequelize('mysql://example.com:9821/dbname', {});
var config = sequelize.config;
expect(config.username).to.not.be.ok;
expect(config.password).to.be.null;
});
it('should use the default port when no other is specified', function() {
var sequelize = new Sequelize('dbname', 'root', 'pass', {
dialect: dialect
})
, config = sequelize.config
, port;
if (Support.dialectIsMySQL()) {
port = 3306;
} else if (dialect === 'postgres' || dialect === 'postgres-native') {
port = 5432;
} else {
// sqlite has no concept of ports when connecting
return;
}
expect(config.port).to.equal(port);
});
});
});
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/support')
, Sequelize = Support.Sequelize;
describe('Sequelize constructor', function () {
describe('options', function() {
it('throw error when no dialect is supplied', function() {
expect(function() {
new Sequelize('localhost', 'test', 'test');
}).to.throw(Error);
});
it('works when dialect explicitly supplied', function() {
expect(function() {
new Sequelize('localhost', 'test', 'test', {
dialect: 'mysql'
});
}).not.to.throw(Error);
});
});
it('should support database, username, password, options', function () {
var database = Math.random().toString()
, username = Math.random().toString()
, password = Math.random().toString()
, host = Math.random().toString()
, port = Math.random().toString();
var sequelize = new Sequelize(database, username, password, {
host: host,
port: port
});
expect(sequelize.config.database).to.equal(database);
expect(sequelize.config.username).to.equal(username);
expect(sequelize.config.password).to.equal(password);
expect(sequelize.config.host).to.equal(host);
expect(sequelize.config.port).to.equal(port);
});
it('should support connection uri, options', function () {
var dialect = 'postgres'
, database = Math.ceil(Math.random() * 9999).toString()
, username = Math.ceil(Math.random() * 9999).toString()
, password = Math.ceil(Math.random() * 9999).toString()
, host = Math.ceil(Math.random() * 9999).toString()
, port = Math.ceil(Math.random() * 9999).toString();
var uri = dialect + '://' + username + ':' + password + '@' + host + ':' + port + '/' + database;
var sequelize = new Sequelize(uri);
expect(sequelize.config.database).to.equal(database);
expect(sequelize.config.username).to.equal(username);
expect(sequelize.config.password).to.equal(password);
expect(sequelize.config.host).to.equal(host);
expect(sequelize.config.port).to.equal(port);
});
it('should support options', function () {
var database = Math.random().toString()
, username = Math.random().toString()
, password = Math.random().toString()
, host = Math.random().toString()
, port = Math.random().toString();
var sequelize = new Sequelize({
host: host,
port: port,
database: database,
username: username,
password: password
});
expect(sequelize.config.database).to.equal(database);
expect(sequelize.config.username).to.equal(username);
expect(sequelize.config.password).to.equal(password);
expect(sequelize.config.host).to.equal(host);
expect(sequelize.config.port).to.equal(port);
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!