Merge branch 'discover-hang' of https://github.com/TorchlightSoftware/loopback-datasource-juggler into TorchlightSoftware-discover-hang

# Conflicts:
#	lib/datasource.js
#	test/discovery.test.js
This commit is contained in:
Raymond Feng 2016-04-05 16:18:25 -07:00
commit daaf5e381a
2 changed files with 26 additions and 2 deletions

View File

@ -1237,7 +1237,7 @@ DataSource.prototype.discoverSchema = function(modelName, options, cb) {
cb = cb || utils.createPromiseCallback();
this.discoverSchemas(modelName, options, function(err, schemas) {
if (err) {
if (err || !schemas) {
cb && cb(err, schemas);
return;
}
@ -1316,7 +1316,7 @@ DataSource.prototype.discoverSchemas = function(modelName, options, cb) {
var columns = results[0];
if (!columns || columns.length === 0) {
cb();
cb(new Error('Table \'' + modelName + '\' does not exist.'));
return cb.promise;
}

View File

@ -625,3 +625,27 @@ describe('Mock connector', function() {
});
});
});
describe('Default memory connector', function() {
var ds, nonExistantError = 'Table \'NONEXISTENT\' does not exist.';
before(function() {
ds = new DataSource({ connector: 'memory' });
});
it('discoverSchema should return an error when table does not exist', function(done) {
ds.discoverSchema('NONEXISTENT', {}, function(err, schemas) {
should.exist(err);
err.message.should.eql(nonExistantError);
done();
});
});
it('discoverSchemas should return an error when table does not exist', function(done) {
ds.discoverSchemas('NONEXISTENT', {}, function(err, schemas) {
should.exist(err);
err.message.should.eql(nonExistantError);
done();
});
});
});