10
10
*
11
11
*/
12
12
13
- import { CheckStatus , ZosmfSession } from "@brightside/core" ;
14
- import { IHandlerParameters , Imperative , ImperativeError } from "@zowe/imperative" ;
13
+ import { IHandlerParameters , ImperativeError } from "@zowe/imperative" ;
15
14
import * as DeployBundleDefinition from "../../../../src/cli/deploy/bundle/DeployBundle.definition" ;
16
15
import * as DeployBundleHandler from "../../../../src/cli/deploy/bundle/DeployBundle.handler" ;
17
- import * as fs from "fs" ;
18
16
19
17
process . env . FORCE_COLOR = "0" ;
20
18
@@ -82,9 +80,7 @@ describe("bundle Handler", () => {
82
80
} catch ( e ) {
83
81
err = e ;
84
82
}
85
- expect ( err ) . toBeUndefined ( ) ;
86
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
87
- expect ( params . arguments . errorMsg ) . toContain ( "--name parameter is not a string" ) ;
83
+ expectImperativeErrorWithMessage ( err , "--name parameter is not a string" ) ;
88
84
} ) ;
89
85
it ( "should complain with overlong name parameter" , async ( ) => {
90
86
await testNameError ( "123456789" , "--name parameter is too long" ) ;
@@ -108,9 +104,7 @@ describe("bundle Handler", () => {
108
104
} catch ( e ) {
109
105
err = e ;
110
106
}
111
- expect ( err ) . toBeUndefined ( ) ;
112
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
113
- expect ( params . arguments . errorMsg ) . toContain ( "--bundledir parameter is not a string" ) ;
107
+ expectImperativeErrorWithMessage ( err , "--bundledir parameter is not a string" ) ;
114
108
} ) ;
115
109
it ( "should complain with overlong bundledir parameter" , async ( ) => {
116
110
const dir = "12345678901234567890123456789012345678901234567890" +
@@ -142,9 +136,7 @@ describe("bundle Handler", () => {
142
136
} catch ( e ) {
143
137
err = e ;
144
138
}
145
- expect ( err ) . toBeUndefined ( ) ;
146
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
147
- expect ( params . arguments . errorMsg ) . toContain ( "--cics-deploy-profile parameter is not a string" ) ;
139
+ expectImperativeErrorWithMessage ( err , "--cics-deploy-profile parameter is not a string" ) ;
148
140
} ) ;
149
141
it ( "should complain if profile is empty" , async ( ) => {
150
142
await testProfileError ( "" , "--cics-deploy-profile parameter is empty" ) ;
@@ -162,9 +154,7 @@ describe("bundle Handler", () => {
162
154
} catch ( e ) {
163
155
err = e ;
164
156
}
165
- expect ( err ) . toBeUndefined ( ) ;
166
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
167
- expect ( params . arguments . errorMsg ) . toContain ( "--cicsplex parameter is not a string" ) ;
157
+ expectImperativeErrorWithMessage ( err , "--cicsplex parameter is not a string" ) ;
168
158
} ) ;
169
159
it ( "should complain with overlong cicsplex parameter" , async ( ) => {
170
160
await testCicsplexError ( "123456789" , "--cicsplex parameter is too long" ) ;
@@ -185,9 +175,7 @@ describe("bundle Handler", () => {
185
175
} catch ( e ) {
186
176
err = e ;
187
177
}
188
- expect ( err ) . toBeUndefined ( ) ;
189
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
190
- expect ( params . arguments . errorMsg ) . toContain ( "--scope parameter is not a string" ) ;
178
+ expectImperativeErrorWithMessage ( err , "--scope parameter is not a string" ) ;
191
179
} ) ;
192
180
it ( "should complain with overlong scope parameter" , async ( ) => {
193
181
await testScopeError ( "123456789" , "--scope parameter is too long" ) ;
@@ -208,9 +196,7 @@ describe("bundle Handler", () => {
208
196
} catch ( e ) {
209
197
err = e ;
210
198
}
211
- expect ( err ) . toBeUndefined ( ) ;
212
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
213
- expect ( params . arguments . errorMsg ) . toContain ( "--csdgroup parameter is not a string" ) ;
199
+ expectImperativeErrorWithMessage ( err , "--csdgroup parameter is not a string" ) ;
214
200
} ) ;
215
201
it ( "should complain with overlong csdgroup parameter" , async ( ) => {
216
202
await testCsdgroupError ( "123456789" , "--csdgroup parameter is too long" ) ;
@@ -232,9 +218,7 @@ describe("bundle Handler", () => {
232
218
} catch ( e ) {
233
219
err = e ;
234
220
}
235
- expect ( err ) . toBeUndefined ( ) ;
236
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
237
- expect ( params . arguments . errorMsg ) . toContain ( "--csdgroup and --resgroup cannot both be set" ) ;
221
+ expectImperativeErrorWithMessage ( err , "--csdgroup and --resgroup cannot both be set" ) ;
238
222
} ) ;
239
223
it ( "should complain with invalid type for resgroup parameter" , async ( ) => {
240
224
@@ -249,9 +233,7 @@ describe("bundle Handler", () => {
249
233
} catch ( e ) {
250
234
err = e ;
251
235
}
252
- expect ( err ) . toBeUndefined ( ) ;
253
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
254
- expect ( params . arguments . errorMsg ) . toContain ( "--resgroup parameter is not a string" ) ;
236
+ expectImperativeErrorWithMessage ( err , "--resgroup parameter is not a string" ) ;
255
237
} ) ;
256
238
it ( "should complain with overlong resgroup parameter" , async ( ) => {
257
239
await testResgroupError ( "123456789" , "--resgroup parameter is too long" ) ;
@@ -272,9 +254,7 @@ describe("bundle Handler", () => {
272
254
} catch ( e ) {
273
255
err = e ;
274
256
}
275
- expect ( err ) . toBeUndefined ( ) ;
276
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
277
- expect ( params . arguments . errorMsg ) . toContain ( "--timeout parameter is not an integer" ) ;
257
+ expectImperativeErrorWithMessage ( err , "--timeout parameter is not an integer" ) ;
278
258
} ) ;
279
259
it ( "should complain with non-integer timeout" , async ( ) => {
280
260
await testTimeoutError ( 1.1 , "--timeout parameter is not an integer" ) ;
@@ -301,9 +281,7 @@ describe("bundle Handler", () => {
301
281
} catch ( e ) {
302
282
err = e ;
303
283
}
304
- expect ( err ) . toBeUndefined ( ) ;
305
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
306
- expect ( params . arguments . errorMsg ) . toContain ( "--cicshlq parameter is not a string" ) ;
284
+ expectImperativeErrorWithMessage ( err , "--cicshlq parameter is not a string" ) ;
307
285
} ) ;
308
286
it ( "should complain with overlong cicshlq parameter" , async ( ) => {
309
287
await testCicsHLQError ( "123456789012345678901234567890123456" , "--cicshlq parameter is too long" ) ;
@@ -327,9 +305,7 @@ describe("bundle Handler", () => {
327
305
} catch ( e ) {
328
306
err = e ;
329
307
}
330
- expect ( err ) . toBeUndefined ( ) ;
331
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
332
- expect ( params . arguments . errorMsg ) . toContain ( "--cpsmhlq parameter is not a string" ) ;
308
+ expectImperativeErrorWithMessage ( err , "--cpsmhlq parameter is not a string" ) ;
333
309
} ) ;
334
310
it ( "should complain with overlong cpsmhlq parameter" , async ( ) => {
335
311
await testCpsmHLQError ( "123456789012345678901234567890123456" , "--cpsmhlq parameter is too long" ) ;
@@ -353,9 +329,7 @@ describe("bundle Handler", () => {
353
329
} catch ( e ) {
354
330
err = e ;
355
331
}
356
- expect ( err ) . toBeUndefined ( ) ;
357
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
358
- expect ( params . arguments . errorMsg ) . toContain ( "--jobcard parameter is not a string" ) ;
332
+ expectImperativeErrorWithMessage ( err , "--jobcard parameter is not a string" ) ;
359
333
} ) ;
360
334
it ( "should complain with empty jobcard parameter" , async ( ) => {
361
335
await testJobcardError ( "" , "--jobcard parameter is empty" ) ;
@@ -391,9 +365,7 @@ describe("bundle Handler", () => {
391
365
} catch ( e ) {
392
366
err = e ;
393
367
}
394
- expect ( err ) . toBeUndefined ( ) ;
395
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
396
- expect ( params . arguments . errorMsg ) . toContain ( "--targetstate parameter is not a string" ) ;
368
+ expectImperativeErrorWithMessage ( err , "--targetstate parameter is not a string" ) ;
397
369
} ) ;
398
370
it ( "should complain with empty targetstate parameter" , async ( ) => {
399
371
await testTargetStateDeployError ( "" , "--targetstate parameter is empty" ) ;
@@ -415,9 +387,7 @@ describe("bundle Handler", () => {
415
387
} catch ( e ) {
416
388
err = e ;
417
389
}
418
- expect ( err ) . toBeUndefined ( ) ;
419
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
420
- expect ( params . arguments . errorMsg ) . toContain ( "--verbose parameter is not boolean" ) ;
390
+ expectImperativeErrorWithMessage ( err , "--verbose parameter is not boolean" ) ;
421
391
} ) ;
422
392
it ( "should complain if zosmf profile not found" , async ( ) => {
423
393
@@ -433,9 +403,7 @@ describe("bundle Handler", () => {
433
403
} catch ( e ) {
434
404
err = e ;
435
405
}
436
- expect ( err ) . toBeUndefined ( ) ;
437
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
438
- expect ( params . arguments . errorMsg ) . toContain ( "No zosmf profile found" ) ;
406
+ expectImperativeErrorWithMessage ( err , "No zosmf profile found" ) ;
439
407
} ) ;
440
408
} ) ;
441
409
@@ -467,9 +435,7 @@ async function testNameError(name: string, result: string) {
467
435
} catch ( e ) {
468
436
err = e ;
469
437
}
470
- expect ( err ) . toBeUndefined ( ) ;
471
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
472
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
438
+ expectImperativeErrorWithMessage ( err , result ) ;
473
439
}
474
440
475
441
function setCommonParmsForBundledirTests ( parms : IHandlerParameters ) {
@@ -489,9 +455,7 @@ async function testBundledirError(bundledir: string, result: string) {
489
455
} catch ( e ) {
490
456
err = e ;
491
457
}
492
- expect ( err ) . toBeUndefined ( ) ;
493
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
494
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
458
+ expectImperativeErrorWithMessage ( err , result ) ;
495
459
}
496
460
497
461
function setCommonParmsForProfileTests ( parms : IHandlerParameters ) {
@@ -511,9 +475,7 @@ async function testProfileError(profile: string, result: string) {
511
475
} catch ( e ) {
512
476
err = e ;
513
477
}
514
- expect ( err ) . toBeUndefined ( ) ;
515
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
516
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
478
+ expectImperativeErrorWithMessage ( err , result ) ;
517
479
}
518
480
519
481
function setCommonParmsForCicsplexTests ( parms : IHandlerParameters ) {
@@ -533,9 +495,7 @@ async function testCicsplexError(cicsplex: string, result: string) {
533
495
} catch ( e ) {
534
496
err = e ;
535
497
}
536
- expect ( err ) . toBeUndefined ( ) ;
537
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
538
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
498
+ expectImperativeErrorWithMessage ( err , result ) ;
539
499
}
540
500
541
501
function setCommonParmsForScopeTests ( parms : IHandlerParameters ) {
@@ -556,9 +516,7 @@ async function testScopeError(scope: string, result: string) {
556
516
} catch ( e ) {
557
517
err = e ;
558
518
}
559
- expect ( err ) . toBeUndefined ( ) ;
560
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
561
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
519
+ expectImperativeErrorWithMessage ( err , result ) ;
562
520
}
563
521
564
522
function setCommonParmsForCsdgroupTests ( parms : IHandlerParameters ) {
@@ -578,9 +536,7 @@ async function testCsdgroupError(csdgroup: string, result: string) {
578
536
} catch ( e ) {
579
537
err = e ;
580
538
}
581
- expect ( err ) . toBeUndefined ( ) ;
582
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
583
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
539
+ expectImperativeErrorWithMessage ( err , result ) ;
584
540
}
585
541
586
542
function setCommonParmsForResgroupTests ( parms : IHandlerParameters ) {
@@ -599,9 +555,7 @@ async function testResgroupError(resgroup: string, result: string) {
599
555
} catch ( e ) {
600
556
err = e ;
601
557
}
602
- expect ( err ) . toBeUndefined ( ) ;
603
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
604
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
558
+ expectImperativeErrorWithMessage ( err , result ) ;
605
559
}
606
560
607
561
function setCommonParmsForTimeoutTests ( parms : IHandlerParameters ) {
@@ -621,9 +575,7 @@ async function testTimeoutError(timeout: number, result: string) {
621
575
} catch ( e ) {
622
576
err = e ;
623
577
}
624
- expect ( err ) . toBeUndefined ( ) ;
625
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
626
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
578
+ expectImperativeErrorWithMessage ( err , ( result ) ) ;
627
579
}
628
580
629
581
function setCommonParmsForCicsHLQTests ( parms : IHandlerParameters ) {
@@ -642,9 +594,7 @@ async function testCicsHLQError(cicshlq: string, result: string) {
642
594
} catch ( e ) {
643
595
err = e ;
644
596
}
645
- expect ( err ) . toBeUndefined ( ) ;
646
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
647
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
597
+ expectImperativeErrorWithMessage ( err , result ) ;
648
598
}
649
599
650
600
function setCommonParmsForCpsmHLQTests ( parms : IHandlerParameters ) {
@@ -664,9 +614,7 @@ async function testCpsmHLQError(cpsmhlq: string, result: string) {
664
614
} catch ( e ) {
665
615
err = e ;
666
616
}
667
- expect ( err ) . toBeUndefined ( ) ;
668
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
669
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
617
+ expectImperativeErrorWithMessage ( err , result ) ;
670
618
}
671
619
672
620
function setCommonParmsForJobcardTests ( parms : IHandlerParameters ) {
@@ -687,9 +635,7 @@ async function testJobcardError(jobcard: string, result: string) {
687
635
} catch ( e ) {
688
636
err = e ;
689
637
}
690
- expect ( err ) . toBeUndefined ( ) ;
691
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
692
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
638
+ expectImperativeErrorWithMessage ( err , result ) ;
693
639
}
694
640
695
641
function setCommonParmsForTargetStateTests ( parms : IHandlerParameters ) {
@@ -709,7 +655,11 @@ async function testTargetStateDeployError(targetstate: string, result: string) {
709
655
} catch ( e ) {
710
656
err = e ;
711
657
}
712
- expect ( err ) . toBeUndefined ( ) ;
713
- expect ( params . arguments . errorMsg ) . toBeDefined ( ) ;
714
- expect ( params . arguments . errorMsg ) . toContain ( result ) ;
658
+ expectImperativeErrorWithMessage ( err , result ) ;
659
+ }
660
+
661
+ function expectImperativeErrorWithMessage ( err : any , message : string ) {
662
+ expect ( err ) . toBeDefined ( ) ;
663
+ expect ( err ) . toBeInstanceOf ( ImperativeError ) ;
664
+ expect ( err . message ) . toContain ( message ) ;
715
665
}
0 commit comments