mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
v1 of the redis driver wrapper
This commit is contained in:
commit
629241611b
5 changed files with 144 additions and 0 deletions
11
libraries/redis-wrapper/.gitignore
vendored
Normal file
11
libraries/redis-wrapper/.gitignore
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
**.swp
|
||||
|
||||
app.js
|
||||
app/js/
|
||||
test/unit/js/
|
||||
public/build/
|
||||
|
||||
node_modules/
|
||||
|
||||
/public/js/chat.js
|
||||
plato/
|
35
libraries/redis-wrapper/Gruntfile.coffee
Normal file
35
libraries/redis-wrapper/Gruntfile.coffee
Normal file
|
@ -0,0 +1,35 @@
|
|||
module.exports = (grunt) ->
|
||||
|
||||
# Project configuration.
|
||||
grunt.initConfig
|
||||
coffee:
|
||||
server:
|
||||
expand: true,
|
||||
flatten: false,
|
||||
cwd: 'app/coffee',
|
||||
src: ['**/*.coffee'],
|
||||
dest: 'app/js/',
|
||||
ext: '.js'
|
||||
|
||||
server_tests:
|
||||
expand: true,
|
||||
flatten: false,
|
||||
cwd: 'test/unit/coffee',
|
||||
src: ['**/*.coffee'],
|
||||
dest: 'test/unit/js/',
|
||||
ext: '.js'
|
||||
|
||||
mochaTest:
|
||||
unit:
|
||||
options:
|
||||
reporter: process.env.MOCHA_RUNNER || "spec"
|
||||
grep: grunt.option("grep")
|
||||
require: 'coffee-script/register'
|
||||
src: ['test.coffee']
|
||||
|
||||
|
||||
grunt.loadNpmTasks 'grunt-contrib-coffee'
|
||||
grunt.loadNpmTasks 'grunt-mocha-test'
|
||||
|
||||
grunt.registerTask 'test:unit', ['mochaTest:unit']
|
||||
|
10
libraries/redis-wrapper/index.coffee
Normal file
10
libraries/redis-wrapper/index.coffee
Normal file
|
@ -0,0 +1,10 @@
|
|||
module.exports =
|
||||
|
||||
createClient: ()->
|
||||
if arguments[0] instanceof Array
|
||||
client = require("redis-sentinel").createClient.apply null, arguments
|
||||
else
|
||||
client = require("redis").createClient.apply null, arguments
|
||||
return client
|
||||
|
||||
|
23
libraries/redis-wrapper/package.json
Normal file
23
libraries/redis-wrapper/package.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "redis-sharelatex",
|
||||
"version": "0.0.0",
|
||||
"description": "",
|
||||
"main": "index.coffee",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"chai": "^1.9.1",
|
||||
"coffee-script": "^1.8.0",
|
||||
"grunt": "^0.4.5",
|
||||
"grunt-contrib-coffee": "^0.11.1",
|
||||
"grunt-mocha-test": "^0.12.0",
|
||||
"mocha": "^1.21.4",
|
||||
"redis": "^0.12.1",
|
||||
"redis-sentinel": "^0.1.1",
|
||||
"sandboxed-module": "^1.0.1",
|
||||
"sinon": "^1.10.3"
|
||||
}
|
||||
}
|
65
libraries/redis-wrapper/test.coffee
Normal file
65
libraries/redis-wrapper/test.coffee
Normal file
|
@ -0,0 +1,65 @@
|
|||
should = require('chai').should()
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
path = require('path')
|
||||
sinon = require('sinon')
|
||||
modulePath = path.join __dirname, "./index.coffee"
|
||||
expect = require("chai").expect
|
||||
|
||||
describe "index", ->
|
||||
|
||||
beforeEach ->
|
||||
|
||||
@settings = {}
|
||||
@sentinelClient = set:->
|
||||
@normalRedisClient = get: ->
|
||||
|
||||
@sentinel =
|
||||
createClient: sinon.stub().returns(@sentinelClient)
|
||||
@normalRedis =
|
||||
createClient: sinon.stub().returns(@normalRedisClient)
|
||||
@redis = SandboxedModule.require modulePath, requires:
|
||||
"redis-sentinel":@sentinel
|
||||
"redis":@normalRedis
|
||||
@standardOpts =
|
||||
auth_pass: "my password"
|
||||
|
||||
describe "sentinel", ->
|
||||
|
||||
beforeEach ->
|
||||
@endpoints = [
|
||||
{host: '127.0.0.1', port: 26379},
|
||||
{host: '127.0.0.1', port: 26380}
|
||||
]
|
||||
@masterName = "my master"
|
||||
|
||||
it "should use sentinal if the first argument in an array", ->
|
||||
|
||||
client = @redis.createClient @endpoints, @masterName, @standardOpts
|
||||
@sentinel.createClient.called.should.equal true
|
||||
@normalRedis.createClient.called.should.equal false
|
||||
client.should.equal @sentinelClient
|
||||
|
||||
it "should pass the options correctly though", ->
|
||||
client = @redis.createClient @endpoints, @masterName, @standardOpts
|
||||
@sentinel.createClient.calledWith(@endpoints, @masterName, @standardOpts).should.equal true
|
||||
client.should.equal @sentinelClient
|
||||
|
||||
describe "normal redis", ->
|
||||
|
||||
beforeEach ->
|
||||
@port = 1234
|
||||
@host = "redis.mysite.env"
|
||||
|
||||
it "should use the normal redis driver if a non array is passed", ->
|
||||
|
||||
client = @redis.createClient @port, @host, @standardOpts
|
||||
@sentinel.createClient.called.should.equal false
|
||||
@normalRedis.createClient.called.should.equal true
|
||||
client.should.equal @normalRedisClient
|
||||
|
||||
|
||||
it "should use the normal redis driver if a non array is passed", ->
|
||||
|
||||
client = @redis.createClient @port, @host, @standardOpts
|
||||
@normalRedis.createClient.calledWith(@port, @host, @standardOpts).should.equal true
|
Loading…
Reference in a new issue