Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should throw cache update error if store op fails', () => {
putStub = sandbox.stub(Etcd3.prototype, 'put', (k) => new PutStubber(hash, k, true));
containsStub = sandbox.stub(subject, 'containsDeployment', () => Promise.resolve(false));
return subject.saveDeployment('plan_id', '5', {}, {}).catch(err => {
expect(err.code).to.eql('ETCDERROR');
});
});
});
it('should return true if task is in cache', () => {
getStub = sandbox.stub(Etcd3.prototype, 'get', (k) => new SingleRangeStubber(hash, k));
return subject.containsBoshTask('1').then(o => {
expect(o).to.eql(true);
});
});
it('should return false if task is not in cache', () => {
it('should store deployment in cache if absent previously', () => {
putStub = sandbox.stub(Etcd3.prototype, 'put', (k) => new PutStubber(hash, k));
containsStub = sandbox.stub(subject, 'containsDeployment', () => Promise.resolve(false));
return subject.store('plan_id', '4', {
param: 'value'
}, {
arg: 'val'
}).then(o => {
expect(o).to.eql(true);
});
});
it('should not store again if previously present in cache', () => {
it('should return true if task is in cache', () => {
getStub = sandbox.stub(Etcd3.prototype, 'get', (k) => new SingleRangeStubber(hash, k));
return subject.containsBoshTask('1').then(o => {
expect(o).to.eql(true);
});
});
it('should return false if task is not in cache', () => {
beforeEach(() => {
sandbox = sinon.sandbox.create();
valueStub = sandbox.stub();
acquireStub = sandbox.stub();
releaseStub = sandbox.stub();
jsonStub = sandbox.stub();
putStub = sandbox.stub(Etcd3.prototype, 'put', () => {
return {
value: (val) => Promise.resolve(valueStub(val))
};
});
getStub = sandbox.stub(Etcd3.prototype, 'get', () => {
return {
json: () => Promise.resolve(jsonStub())
};
});
lockStub = sandbox.stub(Etcd3.prototype, 'lock', () => {
return {
ttl: () => {
return {
acquire: () => Promise.resolve(acquireStub())
};
},
before(() => {
sandbox = sinon.sandbox.create();
valueStub = sandbox.stub();
stringStub = sandbox.stub();
jsonStub = sandbox.stub();
putstub = sandbox.stub(Etcd3.prototype, 'put', () => {
return {
value: (val) => Promise.resolve(valueStub(val))
};
});
getstub = sandbox.stub(Etcd3.prototype, 'get', () => {
return {
json: () => Promise.resolve(jsonStub()),
string: () => Promise.resolve(stringStub()),
};
});
prefixWatcherStub = sandbox.stub().returns({
create: () => Promise.resolve({
on: () => Promise.resolve('prefixWatcherStubResponse')
}),
});
before(() => {
sandbox = sinon.sandbox.create();
valueStub = sandbox.stub();
stringStub = sandbox.stub();
jsonStub = sandbox.stub();
putstub = sandbox.stub(Etcd3.prototype, 'put', () => {
return {
value: (val) => Promise.resolve(valueStub(val))
};
});
getstub = sandbox.stub(Etcd3.prototype, 'get', () => {
return {
json: () => Promise.resolve(jsonStub()),
string: () => Promise.resolve(stringStub()),
};
});
prefixWatcherStub = sandbox.stub().returns({
create: () => Promise.resolve({
on: () => Promise.resolve('prefixWatcherStubResponse')
}),
});
keyWatcherStub = sandbox.stub().returns({
create: () => Promise.resolve({
on: () => Promise.resolve('keyWatcherStubResponse')
}),
});
beforeEach(() => {
sandbox = sinon.sandbox.create();
valueStub = sandbox.stub();
acquireStub = sandbox.stub();
releaseStub = sandbox.stub();
jsonStub = sandbox.stub();
putStub = sandbox.stub(Etcd3.prototype, 'put', () => {
return {
value: (val) => Promise.resolve(valueStub(val))
};
});
getStub = sandbox.stub(Etcd3.prototype, 'get', () => {
return {
json: () => Promise.resolve(jsonStub())
};
});
lockStub = sandbox.stub(Etcd3.prototype, 'lock', () => {
return {
ttl: () => {
return {
acquire: () => Promise.resolve(acquireStub())
};
},
release: () => Promise.resolve(releaseStub())
};
});
});