@@ -421,7 +421,43 @@ func TestShow_planWithForceReplaceChange(t *testing.T) {
421
421
if ! strings .Contains (got , want ) {
422
422
t .Fatalf ("unexpected output\n got: %s\n want: %s" , got , want )
423
423
}
424
+ }
425
+
426
+ func TestShow_planErrored (t * testing.T ) {
427
+ _ , snap := testModuleWithSnapshot (t , "show" )
428
+ plan := testPlan (t )
429
+ plan .Errored = true
430
+ planFilePath := testPlanFile (
431
+ t ,
432
+ snap ,
433
+ states .NewState (),
434
+ plan ,
435
+ )
436
+
437
+ view , done := testView (t )
438
+ c := & ShowCommand {
439
+ Meta : Meta {
440
+ testingOverrides : metaOverridesForProvider (showFixtureProvider ()),
441
+ View : view ,
442
+ },
443
+ }
424
444
445
+ args := []string {
446
+ planFilePath ,
447
+ "-no-color" ,
448
+ }
449
+ code := c .Run (args )
450
+ output := done (t )
451
+
452
+ if code != 0 {
453
+ t .Fatalf ("unexpected exit status %d; want 0\n got: %s" , code , output .Stderr ())
454
+ }
455
+
456
+ got := output .Stdout ()
457
+ want := `Planning failed. Terraform encountered an error while generating this plan.`
458
+ if ! strings .Contains (got , want ) {
459
+ t .Fatalf ("unexpected output\n got: %s\n want: %s" , got , want )
460
+ }
425
461
}
426
462
427
463
func TestShow_plan_json (t * testing.T ) {
@@ -525,6 +561,20 @@ func TestShow_json_output(t *testing.T) {
525
561
t .Fatalf ("init failed\n %s" , ui .ErrorWriter )
526
562
}
527
563
564
+ // read expected output
565
+ wantFile , err := os .Open ("output.json" )
566
+ if err != nil {
567
+ t .Fatalf ("unexpected err: %s" , err )
568
+ }
569
+ defer wantFile .Close ()
570
+ byteValue , err := ioutil .ReadAll (wantFile )
571
+ if err != nil {
572
+ t .Fatalf ("unexpected err: %s" , err )
573
+ }
574
+
575
+ var want plan
576
+ json .Unmarshal ([]byte (byteValue ), & want )
577
+
528
578
// plan
529
579
planView , planDone := testView (t )
530
580
pc := & PlanCommand {
@@ -542,8 +592,15 @@ func TestShow_json_output(t *testing.T) {
542
592
code := pc .Run (args )
543
593
planOutput := planDone (t )
544
594
545
- if code != 0 {
546
- t .Fatalf ("unexpected exit status %d; want 0\n got: %s" , code , planOutput .Stderr ())
595
+ var wantedCode int
596
+ if want .Errored {
597
+ wantedCode = 1
598
+ } else {
599
+ wantedCode = 0
600
+ }
601
+
602
+ if code != wantedCode {
603
+ t .Fatalf ("unexpected exit status %d; want %d\n got: %s" , code , wantedCode , planOutput .Stderr ())
547
604
}
548
605
549
606
// show
@@ -569,22 +626,11 @@ func TestShow_json_output(t *testing.T) {
569
626
}
570
627
571
628
// compare view output to wanted output
572
- var got , want plan
629
+ var got plan
573
630
574
631
gotString := showOutput .Stdout ()
575
632
json .Unmarshal ([]byte (gotString ), & got )
576
633
577
- wantFile , err := os .Open ("output.json" )
578
- if err != nil {
579
- t .Fatalf ("unexpected err: %s" , err )
580
- }
581
- defer wantFile .Close ()
582
- byteValue , err := ioutil .ReadAll (wantFile )
583
- if err != nil {
584
- t .Fatalf ("unexpected err: %s" , err )
585
- }
586
- json .Unmarshal ([]byte (byteValue ), & want )
587
-
588
634
// Disregard format version to reduce needless test fixture churn
589
635
want .FormatVersion = got .FormatVersion
590
636
@@ -1150,6 +1196,7 @@ type plan struct {
1150
1196
OutputChanges map [string ]interface {} `json:"output_changes,omitempty"`
1151
1197
PriorState priorState `json:"prior_state,omitempty"`
1152
1198
Config map [string ]interface {} `json:"configuration,omitempty"`
1199
+ Errored bool `json:"errored"`
1153
1200
}
1154
1201
1155
1202
type priorState struct {
0 commit comments