memdb.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2015 rain1017.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  12. // implied. See the License for the specific language governing
  13. // permissions and limitations under the License. See the AUTHORS file
  14. // for names of contributors.
  15. 'use strict';
  16. var env = require('../env');
  17. var quick = require('../../lib');
  18. var P = quick.Promise;
  19. var logger = quick.logger.getLogger('test', __filename);
  20. describe('memdb test', function(){
  21. beforeEach(env.initMemdbSync);
  22. afterEach(env.closeMemdbSync);
  23. it('load memdb', function(cb){
  24. var app = quick.mocks.app({serverId : 'area1', serverType : 'area'});
  25. var config = JSON.parse(JSON.stringify(env.memdbConfig)); //clone
  26. config.modelsPath = 'lib/mocks/models';
  27. app.set('memdbConfig', config);
  28. app.load(quick.components.memdb);
  29. return P.try(function(){
  30. return P.promisify(app.start, app)();
  31. })
  32. .then(function(){
  33. return app.memdb.goose.autoconn;
  34. })
  35. .then(function(ret){
  36. var autoconn = ret;
  37. return autoconn.transaction(function(){
  38. return P.try(function(){
  39. var dummy = new app.models.Dummy({_id : '1', name : 'dummy'});
  40. return dummy.saveAsync();
  41. })
  42. .then(function(){
  43. return app.models.Dummy.findAsync({_id : '1'});
  44. })
  45. .then(function(dummys){
  46. dummys.length.should.eql(1);
  47. dummys[0].name.should.eql('dummy');
  48. return dummys[0].removeAsync();
  49. });
  50. });
  51. })
  52. .then(function(){
  53. return P.promisify(app.stop, app)();
  54. })
  55. .nodeify(cb);
  56. });
  57. });