UNPKG

poseidon-memcached

Version:

A future wrapper around the Node Memcached driver using Poseidon.

61 lines (54 loc) 1.54 kB
Q = require 'q' {Driver, Cache} = require '../index' Memcached = require 'memcached' describe 'The Cache class', -> beforeEach -> Driver.configure('default', { servers: 'localhost:11212' }) it 'has an internal connection from the driver cache', -> cache = new Cache('default') expect(cache._cache).to.deep.equal Driver._connections['default'] expect(cache._connName).to.equal 'default' it 'has wrapped versions of Memcached functions which return normal values', (next) -> cache = new Cache('default') fns = [ 'get' 'gets' 'getMulti' 'add' 'set' 'del' 'cas' 'flush' ] args = [ ['foo'] ['foo'] ['foo','bar'] ['foo', { foo: 'bar' }, 0] ['foo', { foo: 'bar' }, 0] ['foo'] [] [] ] count = 0 fns.forEach (fn, index) -> sinon.spy(Memcached.prototype, fn) result = cache[fn].apply cache, args[index] expect(Q.isPromise(result)).to.equal true result .fail -> true .finally () -> expect(Memcached.prototype[fn]).to.have.been.called count += 1 Memcached.prototype[fn].restore() if count is fns.length then next() .done() return describe 'the end function', -> it 'calls closeConnection on the Driver', -> cache = new Cache('default') sinon.spy(Driver, 'closeConnection') cache.end() expect(Driver.closeConnection).to.have.been.calledOnce Driver.closeConnection.restore()