Skip to content

Commit

Permalink
fix get options methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pasupulaphani committed Dec 12, 2016
1 parent e88f1e7 commit b3bc5ae
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/redis_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ RedisCache.prototype.wrap = function (key, promise, ttlInSeconds) {
* @returns {string} Name of the pool
*/
RedisCache.prototype.getName = function () {
return this.pool.getName();
return this.store.getName();
};

/**
Expand All @@ -127,7 +127,7 @@ RedisCache.prototype.getName = function () {
* @returns {object} redis options given
*/
RedisCache.prototype.getRedisOptions = function () {
return this.pool.getRedisOptions();
return this.store.getRedisOptions();
};

/**
Expand All @@ -136,7 +136,7 @@ RedisCache.prototype.getRedisOptions = function () {
* @returns {object} pool options given
*/
RedisCache.prototype.getPoolOptions = function () {
return this.pool.getPoolOptions();
return this.store.getPoolOptions();
};

/**
Expand All @@ -145,5 +145,5 @@ RedisCache.prototype.getPoolOptions = function () {
* @returns {object} cache and its store status and stats
*/
RedisCache.prototype.status = function () {
return this.pool.status();
return this.store.status();
};
74 changes: 70 additions & 4 deletions test/redis_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ describe("redisCache", () => {

describe("API", () => {

const name = "testCache";
const redisOptions = {
host: process.env.REDIS_HOST || "127.0.0.1"
};
const cache = new RedisCache({
name: "testCache",
redisOptions: {
host: process.env.REDIS_HOST || "127.0.0.1"
}
name: name,
redisOptions: redisOptions
});

describe("set", () => {
Expand Down Expand Up @@ -134,5 +136,69 @@ describe("redisCache", () => {
.should.eventually.be.empty();
});
});

describe("getName", () => {

it("should set given name", () => {
cache.getName().should.be.equal(name);
});

it("should set random name if not set", () => {

const cache = new RedisCache({
redisOptions: redisOptions
});

cache.getName().should.not.be.empty();
});
});

describe("getRedisOptions", () => {

it("should set given redis options", () => {
cache.getRedisOptions().should.be.equal(redisOptions);
});
});

describe("getPoolOptions", () => {

it("should set given pool options", () => {

const poolOptions = {
min: 2,
max: 4
};
const cache = new RedisCache({
name: name,
redisOptions: redisOptions,
poolOptions: poolOptions
});

cache.getPoolOptions().should.be.equal(poolOptions);
});
});

describe("status", () => {

it("should get store stats", () => {

const name = "testStore";
const poolOptions = {
min: 2,
max: 4
};
const cache = new RedisCache({
name: name,
redisOptions: redisOptions,
poolOptions: poolOptions
});

const status = cache.status();
status.name.should.be.equal(name);
status.size.should.be.equal(poolOptions.min);
status.available.should.be.equal(0);
status.pending.should.be.equal(0);
});
});
});
});

0 comments on commit b3bc5ae

Please sign in to comment.