File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -271,4 +271,18 @@ export abstract class BaseCommand extends ShellRunner {
271
271
// return the consensus nodes
272
272
return consensusNodes ;
273
273
}
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
+ }
274
288
}
Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ describe('BaseCommand', () => {
127
127
} ) ;
128
128
129
129
describe ( 'get consensus nodes' , ( ) => {
130
- it ( 'should return consensus nodes' , ( ) => {
130
+ before ( ( ) => {
131
131
const testLogger = sinon . stub ( ) ;
132
132
const helm = sinon . stub ( ) ;
133
133
const chartManager = sinon . stub ( ) ;
@@ -157,7 +157,9 @@ describe('BaseCommand', () => {
157
157
localConfig,
158
158
remoteConfigManager,
159
159
} ) ;
160
+ } ) ;
160
161
162
+ it ( 'should return consensus nodes' , ( ) => {
161
163
const consensusNodes = baseCmd . getConsensusNodes ( ) ;
162
164
expect ( consensusNodes ) . to . be . an ( 'array' ) ;
163
165
expect ( consensusNodes [ 0 ] . context ) . to . equal ( 'context1' ) ;
@@ -171,5 +173,12 @@ describe('BaseCommand', () => {
171
173
expect ( consensusNodes [ 0 ] . cluster ) . to . equal ( 'cluster' ) ;
172
174
expect ( consensusNodes [ 1 ] . cluster ) . to . equal ( 'cluster2' ) ;
173
175
} ) ;
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
+ } ) ;
174
183
} ) ;
175
184
} ) ;
You can’t perform that action at this time.
0 commit comments