Skip to content

Commit e86e94c

Browse files
committed
added base test for getContexts
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 44703a4 commit e86e94c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/commands/base.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,18 @@ export abstract class BaseCommand extends ShellRunner {
271271
// return the consensus nodes
272272
return consensusNodes;
273273
}
274+
275+
/**
276+
* Gets a list of distinct contexts from the consensus nodes
277+
* @returns an array of context strings
278+
*/
279+
public getContexts(): string[] {
280+
const contexts: string[] = [];
281+
this.getConsensusNodes().forEach(node => {
282+
if (!contexts.includes(node.context)) {
283+
contexts.push(node.context);
284+
}
285+
});
286+
return contexts;
287+
}
274288
}

test/unit/commands/base.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('BaseCommand', () => {
127127
});
128128

129129
describe('get consensus nodes', () => {
130-
it('should return consensus nodes', () => {
130+
before(() => {
131131
const testLogger = sinon.stub();
132132
const helm = sinon.stub();
133133
const chartManager = sinon.stub();
@@ -157,7 +157,9 @@ describe('BaseCommand', () => {
157157
localConfig,
158158
remoteConfigManager,
159159
});
160+
});
160161

162+
it('should return consensus nodes', () => {
161163
const consensusNodes = baseCmd.getConsensusNodes();
162164
expect(consensusNodes).to.be.an('array');
163165
expect(consensusNodes[0].context).to.equal('context1');
@@ -171,5 +173,12 @@ describe('BaseCommand', () => {
171173
expect(consensusNodes[0].cluster).to.equal('cluster');
172174
expect(consensusNodes[1].cluster).to.equal('cluster2');
173175
});
176+
177+
it('should return contexts', () => {
178+
const contexts = baseCmd.getContexts();
179+
expect(contexts).to.be.an('array');
180+
expect(contexts[0]).to.equal('context1');
181+
expect(contexts[1]).to.equal('context2');
182+
});
174183
});
175184
});

0 commit comments

Comments
 (0)