mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #9 from overleaf/bg-fix-tests
fix tests for ioredis as default
This commit is contained in:
commit
1a4d2b092d
1 changed files with 20 additions and 32 deletions
|
@ -11,19 +11,28 @@ describe "index", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
||||||
@settings = {}
|
@settings = {}
|
||||||
@sentinelClient = set:->
|
@sentinelClient =
|
||||||
@normalRedisClient = get: ->
|
set: ->
|
||||||
|
on: ->
|
||||||
|
@normalRedisClient =
|
||||||
|
get: ->
|
||||||
|
on: ->
|
||||||
|
@ioredisConstructor = ioredisConstructor = sinon.stub()
|
||||||
|
|
||||||
@sentinel =
|
@sentinel =
|
||||||
createClient: sinon.stub().returns(@sentinelClient)
|
createClient: sinon.stub().returns(@sentinelClient)
|
||||||
@normalRedis =
|
@normalRedis =
|
||||||
createClient: sinon.stub().returns(@normalRedisClient)
|
createClient: sinon.stub().returns(@normalRedisClient)
|
||||||
|
@ioredis = class IoRedis
|
||||||
|
constructor: ioredisConstructor
|
||||||
|
on: sinon.stub()
|
||||||
|
@ioredis.Cluster = class Cluster
|
||||||
|
constructor: (@config, @options) ->
|
||||||
|
on: sinon.stub()
|
||||||
@redis = SandboxedModule.require modulePath, requires:
|
@redis = SandboxedModule.require modulePath, requires:
|
||||||
"redis-sentinel":@sentinel
|
"redis-sentinel":@sentinel
|
||||||
"redis":@normalRedis
|
"redis":@normalRedis
|
||||||
"ioredis": @ioredis =
|
"ioredis": @ioredis
|
||||||
Cluster: class Cluster
|
|
||||||
constructor: (@config, @options) ->
|
|
||||||
@auth_pass = "1234 pass"
|
@auth_pass = "1234 pass"
|
||||||
@endpoints = [
|
@endpoints = [
|
||||||
{host: '127.0.0.1', port: 26379},
|
{host: '127.0.0.1', port: 26379},
|
||||||
|
@ -49,22 +58,22 @@ describe "index", ->
|
||||||
@sentinel.createClient.calledWith(@endpoints, @masterName, {auth_pass:@auth_pass, retry_max_delay: 5000}).should.equal true
|
@sentinel.createClient.calledWith(@endpoints, @masterName, {auth_pass:@auth_pass, retry_max_delay: 5000}).should.equal true
|
||||||
client.should.equal @sentinelClient
|
client.should.equal @sentinelClient
|
||||||
|
|
||||||
describe "normal redis", ->
|
describe "single node redis", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@standardOpts =
|
@standardOpts =
|
||||||
auth_pass: @auth_pass
|
auth_pass: @auth_pass
|
||||||
port: 1234
|
port: 1234
|
||||||
host: "redis.mysite.env"
|
host: "redis.mysite.env"
|
||||||
|
|
||||||
it "should use the normal redis driver if a non array is passed", ->
|
it "should use the ioredis driver in single-instance mode if a non array is passed", ->
|
||||||
client = @redis.createClient @standardOpts
|
client = @redis.createClient @standardOpts
|
||||||
@sentinel.createClient.called.should.equal false
|
@sentinel.createClient.called.should.equal false
|
||||||
@normalRedis.createClient.called.should.equal true
|
@normalRedis.createClient.called.should.equal false
|
||||||
client.should.equal @normalRedisClient
|
assert.equal(client.constructor, @ioredis)
|
||||||
|
|
||||||
it "should use the normal redis driver if a non array is passed", ->
|
it "should call createClient for the ioredis driver in single-instance mode if a non array is passed", ->
|
||||||
client = @redis.createClient @standardOpts
|
client = @redis.createClient @standardOpts
|
||||||
@normalRedis.createClient.calledWith(@standardOpts.port, @standardOpts.host, {auth_pass:@auth_pass, retry_max_delay: 5000}).should.equal true
|
@ioredisConstructor.calledWith(@standardOpts).should.equal true
|
||||||
|
|
||||||
describe "cluster", ->
|
describe "cluster", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@ -114,24 +123,3 @@ describe "index", ->
|
||||||
@multi.exec @callback
|
@multi.exec @callback
|
||||||
@callback.calledWith("error").should.equal true
|
@callback.calledWith("error").should.equal true
|
||||||
|
|
||||||
describe "setting the password", ->
|
|
||||||
beforeEach ->
|
|
||||||
@standardOpts =
|
|
||||||
password: @auth_pass
|
|
||||||
port: 1234
|
|
||||||
host: "redis.mysite.env"
|
|
||||||
|
|
||||||
@sentinelOptions =
|
|
||||||
endpoints:@endpoints
|
|
||||||
masterName:@masterName
|
|
||||||
password: @auth_pass
|
|
||||||
|
|
||||||
it "should set the auth_pass from password if password exists for normal redis", ->
|
|
||||||
client = @redis.createClient @standardOpts
|
|
||||||
@normalRedis.createClient.calledWith(@standardOpts.port, @standardOpts.host, {auth_pass:@auth_pass, retry_max_delay: 5000}).should.equal true
|
|
||||||
|
|
||||||
it "should set the auth_pass from password if password exists for sentinal", ->
|
|
||||||
client = @redis.createClient @sentinelOptions
|
|
||||||
@sentinel.createClient.calledWith(@endpoints, @masterName, {auth_pass:@auth_pass, retry_max_delay: 5000}).should.equal true
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue