mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Add unit tests for RedisWrapper
This commit is contained in:
parent
d428f9adbc
commit
822f76a883
2 changed files with 67 additions and 1 deletions
|
@ -21,7 +21,7 @@ module.exports = Redis =
|
|||
if redisFeatureSettings?.cluster?
|
||||
logger.log {feature}, "creating redis-cluster client"
|
||||
rclient = new ioredis.Cluster(redisFeatureSettings.cluster)
|
||||
rclient._is_redis_cluster = true
|
||||
rclient.__is_redis_cluster = true
|
||||
else
|
||||
logger.log {feature}, "creating redis client"
|
||||
rclient = redis.createClient(redisFeatureSettings)
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
assert = require("chai").assert
|
||||
sinon = require('sinon')
|
||||
chai = require('chai')
|
||||
should = chai.should()
|
||||
expect = chai.expect
|
||||
modulePath = "../../../../app/js/infrastructure/RedisWrapper.js"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe 'RedisWrapper', ->
|
||||
|
||||
beforeEach ->
|
||||
@featureName = 'somefeature'
|
||||
@settings =
|
||||
redis:
|
||||
web:
|
||||
port:"1234"
|
||||
host:"somewhere"
|
||||
password: "password"
|
||||
somefeature: {}
|
||||
@normalRedisInstance =
|
||||
thisIsANormalRedisInstance: true
|
||||
n: 1
|
||||
@clusterRedisInstance =
|
||||
thisIsAClusterRedisInstance: true
|
||||
n: 2
|
||||
@redis =
|
||||
createClient: sinon.stub().returns(@normalRedisInstance)
|
||||
@ioredis =
|
||||
Cluster: sinon.stub().returns(@clusterRedisInstance)
|
||||
@logger = {log: sinon.stub()}
|
||||
|
||||
@RedisWrapper = SandboxedModule.require modulePath, requires:
|
||||
'logger-sharelatex': @logger
|
||||
'settings-sharelatex': @settings
|
||||
'redis-sharelatex': @redis
|
||||
'ioredis': @ioredis
|
||||
|
||||
describe 'client', ->
|
||||
|
||||
beforeEach ->
|
||||
@call = () =>
|
||||
@RedisWrapper.client(@featureName)
|
||||
|
||||
describe 'when feature uses cluster', ->
|
||||
|
||||
beforeEach ->
|
||||
@settings.redis.somefeature =
|
||||
cluster: [1, 2, 3]
|
||||
|
||||
it 'should return a cluster client', ->
|
||||
client = @call()
|
||||
expect(client).to.equal @clusterRedisInstance
|
||||
expect(client.__is_redis_cluster).to.equal true
|
||||
|
||||
describe 'when feature uses normal redis', ->
|
||||
|
||||
beforeEach ->
|
||||
@settings.redis.somefeature =
|
||||
port:"1234"
|
||||
host:"somewhere"
|
||||
password: "password"
|
||||
|
||||
it 'should return a regular redis client', ->
|
||||
client = @call()
|
||||
expect(client).to.equal @normalRedisInstance
|
||||
expect(client.__is_redis_cluster).to.equal undefined
|
Loading…
Reference in a new issue