Skip to content

Commit bdfdaff

Browse files
BB-727: Update tests to use ZookeeperManager
1 parent 3a1a21c commit bdfdaff

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

tests/unit/notification/configManager/ZookeeperConfigManager.spec.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,40 @@ function checkParentConfigZkNode(manager, cb) {
9494

9595
describe('ZookeeperConfigManager', () => {
9696
const zk = new ZookeeperMock({ doLog: false });
97-
const zkClient = zk.createClient();
98-
const params = {
99-
zkClient,
100-
zkConcurrency: 10,
101-
logger,
102-
};
97+
const zkMock = zk.createClient();
98+
let zkClient;
99+
let params;
100+
101+
before(() => {
102+
// Stub _connect before instantiation to inject mock client
103+
sinon.stub(ZookeeperManager.prototype, '_connect').callsFake(function () {
104+
this.client = zkMock;
105+
});
106+
107+
zkClient = new ZookeeperManager('localhost:2181', {}, logger);
108+
109+
params = {
110+
zkClient,
111+
zkConcurrency: 10,
112+
logger,
113+
};
114+
});
115+
116+
after(() => {
117+
sinon.restore();
118+
zk._resetState();
119+
});
103120

104121
describe('Constructor', () => {
122+
let stub;
105123
function checkConfigParentNodeStub(cb) {
106124
return cb(new Error('error checking config parent node'));
107125
}
108126

109-
after(() => {
110-
sinon.restore();
111-
zk._resetState();
127+
afterEach(() => {
128+
if (stub) {
129+
stub.restore();
130+
}
112131
});
113132

114133
it('constructor and setup checks', done => {
@@ -128,7 +147,7 @@ describe('ZookeeperConfigManager', () => {
128147

129148
it('should return error if checkConfigParentNode fails', done => {
130149
const manager = new ZookeeperConfigManager(params);
131-
sinon.stub(manager, '_checkConfigurationParentNode')
150+
stub = sinon.stub(manager, '_checkConfigurationParentNode')
132151
.callsFake(checkConfigParentNodeStub);
133152
manager.setup(err => {
134153
assert(err);
@@ -250,7 +269,7 @@ describe('ZookeeperConfigManager', () => {
250269
sinon.stub(manager, '_updateLocalStore').yields(null);
251270
manager.setup(err => {
252271
assert.ifError(err);
253-
assert(!(manager._zkClient instanceof ZookeeperManager));
272+
assert.strictEqual(manager._zkClient, zkClient);
254273
done();
255274
});
256275
});

0 commit comments

Comments
 (0)