Skip to content

Commit

Permalink
Fix test by creating memory datasouce when rabbit is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Nov 30, 2016
1 parent a5abdff commit c13c243
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ module.exports = function loopbackComponentMq(app, config) {
// Independent of app boot, add model and ACL
setupModel(app)

// - Update models to work even if rabbit is not there/not booted

// Wait the app to be booted
app.once('booted', () => {

Expand All @@ -30,10 +28,11 @@ module.exports = function loopbackComponentMq(app, config) {
// Get a reference to the configured datasource
const dsName = _.get(app, 'settings.loopback-component-mq.options.dataSource', 'rabbit')
const ds = app.dataSources[dsName]
const dsOptions = _.get(ds, 'settings.options')

// If we have a datasource, wire up Rabbit and set up the topology
if (ds) {
Queue.rabbit = new Rabbit(ds.settings.options || {})
if (ds && dsOptions) {
Queue.rabbit = new Rabbit(dsOptions)
RabbitTopology.setupTopology(Queue)
}

Expand Down
5 changes: 5 additions & 0 deletions lib/setup-model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const _ = require('lodash')
const debug = require('debug')('loopback:component:mq')
const loopback = require('loopback')

module.exports = function setupModelFn(app) {
debug('setupModelFn')
Expand All @@ -10,6 +11,10 @@ module.exports = function setupModelFn(app) {
dataSource = app.dataSources[dataSource]
}

if (!dataSource) {
dataSource = loopback.createDataSource({ connector: loopback.Memory })
}

const newModel = dataSource.createModel('Queue', {}, {
plural: 'Queue',
base: 'Model',
Expand Down

0 comments on commit c13c243

Please sign in to comment.