@@ -43,7 +43,7 @@ func TestRun_AddsEnvVarFile(t *testing.T) {
43
43
// Using version >= 0.10 here so we don't expect any env commands.
44
44
tfVersion , _ := version .NewVersion ("0.10.0" )
45
45
logger := logging .NewNoopLogger (t )
46
- s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec )
46
+ s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec , false )
47
47
48
48
expPlanArgs := []string {"plan" ,
49
49
"-input=false" ,
@@ -104,7 +104,7 @@ func TestRun_UsesDiffPathForProject(t *testing.T) {
104
104
tfDistribution := tf .NewDistributionTerraformWithDownloader (mockDownloader )
105
105
tfVersion , _ := version .NewVersion ("0.10.0" )
106
106
logger := logging .NewNoopLogger (t )
107
- s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec )
107
+ s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec , false )
108
108
ctx := command.ProjectContext {
109
109
Log : logger ,
110
110
Workspace : "default" ,
@@ -185,7 +185,7 @@ Terraform will perform the following actions:
185
185
mockDownloader := mocks .NewMockDownloader ()
186
186
tfDistribution := tf .NewDistributionTerraformWithDownloader (mockDownloader )
187
187
tfVersion , _ := version .NewVersion ("0.10.0" )
188
- s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec )
188
+ s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec , false )
189
189
When (terraform .RunCommandWithVersion (
190
190
Any [command.ProjectContext ](),
191
191
Any [string ](),
@@ -238,7 +238,7 @@ func TestRun_OutputOnErr(t *testing.T) {
238
238
mockDownloader := mocks .NewMockDownloader ()
239
239
tfDistribution := tf .NewDistributionTerraformWithDownloader (mockDownloader )
240
240
tfVersion , _ := version .NewVersion ("0.10.0" )
241
- s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec )
241
+ s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec , false )
242
242
expOutput := "expected output"
243
243
expErrMsg := "error!"
244
244
When (terraform .RunCommandWithVersion (
@@ -265,6 +265,47 @@ func TestRun_OutputOnErr(t *testing.T) {
265
265
Equals (t , expOutput , actOutput )
266
266
}
267
267
268
+ // Test that we strip refresh output from errors if configured to do so.
269
+ func TestRun_StripRefreshOutputOnErr (t * testing.T ) {
270
+ RegisterMockTestingT (t )
271
+ terraform := tfclientmocks .NewMockClient ()
272
+ commitStatusUpdater := runtimemocks .NewMockStatusUpdater ()
273
+ asyncTfExec := runtimemocks .NewMockAsyncTFExec ()
274
+ mockDownloader := mocks .NewMockDownloader ()
275
+ tfDistribution := tf .NewDistributionTerraformWithDownloader (mockDownloader )
276
+ tfVersion , _ := version .NewVersion ("0.14.0" )
277
+ s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec , true )
278
+ tfOutput := `null_resource.hi: Refreshing state... (ID: 217661332516885645)
279
+ null_resource.hi[1]: Refreshing state... (ID: 6064510335076839362)
280
+
281
+ An execution plan has been generated and is shown below.`
282
+ strippedOutput := `
283
+ An execution plan has been generated and is shown below.`
284
+ expErrMsg := "error!"
285
+ When (terraform .RunCommandWithVersion (
286
+ Any [command.ProjectContext ](),
287
+ Any [string ](),
288
+ Any [[]string ](),
289
+ Any [map [string ]string ](),
290
+ Any [tf.Distribution ](),
291
+ Any [* version.Version ](),
292
+ Any [string ]())).
293
+ Then (func (params []Param ) ReturnValues {
294
+ // This code allows us to return different values depending on the
295
+ // tf command being run while still using the wildcard matchers above.
296
+ tfArgs := params [2 ].([]string )
297
+ if stringSliceEquals (tfArgs , []string {"workspace" , "show" }) {
298
+ return []ReturnValue {"default\n " , nil }
299
+ } else if tfArgs [0 ] == "plan" {
300
+ return []ReturnValue {tfOutput , errors .New (expErrMsg )}
301
+ }
302
+ return []ReturnValue {"" , errors .New ("unexpected call to RunCommandWithVersion" )}
303
+ })
304
+ actOutput , actErr := s .Run (command.ProjectContext {Workspace : "default" }, nil , "" , map [string ]string (nil ))
305
+ ErrEquals (t , expErrMsg , actErr )
306
+ Equals (t , strippedOutput , actOutput )
307
+ }
308
+
268
309
// Test that if we're using 0.12, we don't set the optional -var atlantis_repo_name
269
310
// flags because in >= 0.12 you can't set -var flags if those variables aren't
270
311
// being used.
@@ -314,7 +355,7 @@ func TestRun_NoOptionalVarsIn012(t *testing.T) {
314
355
mockDownloader := mocks .NewMockDownloader ()
315
356
tfDistribution := tf .NewDistributionTerraformWithDownloader (mockDownloader )
316
357
tfVersion , _ := version .NewVersion (c .tfVersion )
317
- s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec )
358
+ s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec , false )
318
359
ctx := command.ProjectContext {
319
360
Workspace : "default" ,
320
361
RepoRelDir : "." ,
@@ -406,7 +447,7 @@ locally at this time.
406
447
tfDistribution := tf .NewDistributionTerraformWithDownloader (mockDownloader )
407
448
tfVersion , _ := version .NewVersion (c .tfVersion )
408
449
asyncTf := & remotePlanMock {}
409
- s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTf )
450
+ s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTf , false )
410
451
absProjectPath := t .TempDir ()
411
452
412
453
// First, terraform workspace gets run.
@@ -603,7 +644,7 @@ func TestPlanStepRunner_TestRun_UsesConfiguredDistribution(t *testing.T) {
603
644
mockDownloader := mocks .NewMockDownloader ()
604
645
tfDistribution := tf .NewDistributionTerraformWithDownloader (mockDownloader )
605
646
tfVersion , _ := version .NewVersion (c .tfVersion )
606
- s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec )
647
+ s := runtime .NewPlanStepRunner (terraform , tfDistribution , tfVersion , commitStatusUpdater , asyncTfExec , false )
607
648
ctx := command.ProjectContext {
608
649
Workspace : "default" ,
609
650
RepoRelDir : "." ,
0 commit comments