From b556d961486c92567574504e727a47082a21f925 Mon Sep 17 00:00:00 2001 From: bitmage Date: Fri, 22 Jan 2016 10:41:06 -0700 Subject: [PATCH] discoverSchemas returns an error when modelName is not found, discoverSchema forwards that error and does not hang when no columns, no errors are returned --- lib/datasource.js | 4 ++-- test/discovery.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/datasource.js b/lib/datasource.js index 5e7bf66b..e5826ed8 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -1225,7 +1225,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; } @@ -1305,7 +1305,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; } diff --git a/test/discovery.test.js b/test/discovery.test.js index 26e5056c..3bd9e3df 100644 --- a/test/discovery.test.js +++ b/test/discovery.test.js @@ -602,3 +602,27 @@ describe('discoverExportedForeignKeys', 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(); + }); + }); +});