4
4
"fmt"
5
5
"github.com/diggerhq/digger/libs/ci"
6
6
"github.com/diggerhq/digger/libs/execution"
7
+ "github.com/diggerhq/digger/libs/iac_utils"
7
8
orchestrator "github.com/diggerhq/digger/libs/scheduler"
8
9
"os"
9
10
"sort"
@@ -55,13 +56,13 @@ func (m *MockTerraformExecutor) Destroy(params []string, envs map[string]string)
55
56
return "" , "" , nil
56
57
}
57
58
58
- func (m * MockTerraformExecutor ) Show (params []string , envs map [string ]string ) (string , string , error ) {
59
+ func (m * MockTerraformExecutor ) Show (params []string , envs map [string ]string , planJsonFilePath string ) (string , string , error ) {
59
60
nonEmptyTerraformPlanJson := "{\" format_version\" :\" 1.1\" ,\" terraform_version\" :\" 1.4.6\" ,\" planned_values\" :{\" root_module\" :{\" resources\" :[{\" address\" :\" null_resource.test\" ,\" mode\" :\" managed\" ,\" type\" :\" null_resource\" ,\" name\" :\" test\" ,\" provider_name\" :\" registry.terraform.io/hashicorp/null\" ,\" schema_version\" :0,\" values\" :{\" id\" :\" 7587790946951100994\" ,\" triggers\" :null},\" sensitive_values\" :{}},{\" address\" :\" null_resource.testx\" ,\" mode\" :\" managed\" ,\" type\" :\" null_resource\" ,\" name\" :\" testx\" ,\" provider_name\" :\" registry.terraform.io/hashicorp/null\" ,\" schema_version\" :0,\" values\" :{\" triggers\" :null},\" sensitive_values\" :{}}]}},\" resource_changes\" :[{\" address\" :\" null_resource.test\" ,\" mode\" :\" managed\" ,\" type\" :\" null_resource\" ,\" name\" :\" test\" ,\" provider_name\" :\" registry.terraform.io/hashicorp/null\" ,\" change\" :{\" actions\" :[\" no-op\" ],\" before\" :{\" id\" :\" 7587790946951100994\" ,\" triggers\" :null},\" after\" :{\" id\" :\" 7587790946951100994\" ,\" triggers\" :null},\" after_unknown\" :{},\" before_sensitive\" :{},\" after_sensitive\" :{}}},{\" address\" :\" null_resource.testx\" ,\" mode\" :\" managed\" ,\" type\" :\" null_resource\" ,\" name\" :\" testx\" ,\" provider_name\" :\" registry.terraform.io/hashicorp/null\" ,\" change\" :{\" actions\" :[\" create\" ],\" before\" :null,\" after\" :{\" triggers\" :null},\" after_unknown\" :{\" id\" :true},\" before_sensitive\" :false,\" after_sensitive\" :{}}}],\" prior_state\" :{\" format_version\" :\" 1.0\" ,\" terraform_version\" :\" 1.4.6\" ,\" values\" :{\" root_module\" :{\" resources\" :[{\" address\" :\" null_resource.test\" ,\" mode\" :\" managed\" ,\" type\" :\" null_resource\" ,\" name\" :\" test\" ,\" provider_name\" :\" registry.terraform.io/hashicorp/null\" ,\" schema_version\" :0,\" values\" :{\" id\" :\" 7587790946951100994\" ,\" triggers\" :null},\" sensitive_values\" :{}}]}}},\" configuration\" :{\" provider_config\" :{\" null\" :{\" name\" :\" null\" ,\" full_name\" :\" registry.terraform.io/hashicorp/null\" }},\" root_module\" :{\" resources\" :[{\" address\" :\" null_resource.test\" ,\" mode\" :\" managed\" ,\" type\" :\" null_resource\" ,\" name\" :\" test\" ,\" provider_config_key\" :\" null\" ,\" schema_version\" :0},{\" address\" :\" null_resource.testx\" ,\" mode\" :\" managed\" ,\" type\" :\" null_resource\" ,\" name\" :\" testx\" ,\" provider_config_key\" :\" null\" ,\" schema_version\" :0}]}}}\n "
60
61
m .Commands = append (m .Commands , RunInfo {"Show" , strings .Join (params , " " ), time .Now ()})
61
62
return nonEmptyTerraformPlanJson , "" , nil
62
63
}
63
64
64
- func (m * MockTerraformExecutor ) Plan (params []string , envs map [string ]string ) (bool , string , string , error ) {
65
+ func (m * MockTerraformExecutor ) Plan (params []string , envs map [string ]string , planJsonFilePath string ) (bool , string , string , error ) {
65
66
m .Commands = append (m .Commands , RunInfo {"Plan" , strings .Join (params , " " ), time .Now ()})
66
67
return true , "" , "" , nil
67
68
}
@@ -279,13 +280,14 @@ func TestCorrectCommandExecutionWhenApplying(t *testing.T) {
279
280
Reporter : reporter ,
280
281
PlanStorage : planStorage ,
281
282
PlanPathProvider : planPathProvider ,
283
+ IacUtils : iac_utils.TerraformUtils {},
282
284
}
283
285
284
286
executor .Apply ()
285
287
286
288
commandStrings := allCommandsInOrderWithParams (terraformExecutor , commandRunner , prManager , lock , planStorage , planPathProvider )
287
289
288
- assert .Equal (t , []string {"RetrievePlan plan" , "Init " , "Apply -lock-timeout=3m " , "PublishComment 1 <details ><summary>Apply output</summary>\n \n ```terraform\n \n ```\n </details>" , "Run echo" }, commandStrings )
290
+ assert .Equal (t , []string {"RetrievePlan plan" , "Init " , "Apply " , "PublishComment 1 <details ><summary>Apply output</summary>\n \n ```terraform\n \n ```\n </details>" , "Run echo" }, commandStrings )
289
291
}
290
292
291
293
func TestCorrectCommandExecutionWhenDestroying (t * testing.T ) {
@@ -368,6 +370,7 @@ func TestCorrectCommandExecutionWhenPlanning(t *testing.T) {
368
370
Reporter : reporter ,
369
371
PlanStorage : planStorage ,
370
372
PlanPathProvider : planPathProvider ,
373
+ IacUtils : iac_utils.TerraformUtils {},
371
374
}
372
375
373
376
os .WriteFile (planPathProvider .LocalPlanFilePath (), []byte {123 }, 0644 )
@@ -377,7 +380,7 @@ func TestCorrectCommandExecutionWhenPlanning(t *testing.T) {
377
380
378
381
commandStrings := allCommandsInOrderWithParams (terraformExecutor , commandRunner , prManager , lock , planStorage , planPathProvider )
379
382
380
- assert .Equal (t , []string {"Init " , "Plan -out plan -lock-timeout=3m " , "Show -no-color -json plan " , "StorePlanFile plan" , "Run echo" }, commandStrings )
383
+ assert .Equal (t , []string {"Init " , "Plan " , "Show " , "StorePlanFile plan" , "Run echo" }, commandStrings )
381
384
}
382
385
383
386
func allCommandsInOrderWithParams (terraformExecutor * MockTerraformExecutor , commandRunner * MockCommandRunner , prManager * MockPRManager , lock * MockProjectLock , planStorage * MockPlanStorage , planPathProvider * MockPlanPathProvider ) []string {
0 commit comments