backend.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2015 The MemDB Authors.
  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 P = require('bluebird');
  17. var should = require('should');
  18. var memdb = require('../../lib');
  19. var env = require('../env');
  20. var logger = require('memdb-logger').getLogger('test', __filename);
  21. describe('access backend test', function(){
  22. it('connect backend', function(cb){
  23. var db = null, errCount = 0;
  24. return P.try(function(){
  25. return memdb.connectBackend(env.config.backend);
  26. })
  27. .then(function(ret){
  28. db = ret;
  29. // find should success
  30. return db.collection('player').findOneAsync()
  31. .then(function(doc){
  32. logger.info('%j', doc);
  33. });
  34. })
  35. .then(function(){
  36. return db.collection('player').removeAsync()
  37. .catch(function(e){
  38. logger.warn(e.stack);
  39. // could not write, should throw error;
  40. errCount++;
  41. });
  42. })
  43. .then(function(){
  44. errCount.should.eql(1);
  45. })
  46. .nodeify(cb);
  47. });
  48. });