44 "fmt"
55 "github.com/diggerhq/digger/libs/ci"
66 "github.com/diggerhq/digger/libs/execution"
7+ "github.com/diggerhq/digger/libs/iac_utils"
78 orchestrator "github.com/diggerhq/digger/libs/scheduler"
89 "os"
910 "sort"
@@ -55,13 +56,13 @@ func (m *MockTerraformExecutor) Destroy(params []string, envs map[string]string)
5556 return "" , "" , nil
5657}
5758
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 ) {
5960 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 "
6061 m .Commands = append (m .Commands , RunInfo {"Show" , strings .Join (params , " " ), time .Now ()})
6162 return nonEmptyTerraformPlanJson , "" , nil
6263}
6364
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 ) {
6566 m .Commands = append (m .Commands , RunInfo {"Plan" , strings .Join (params , " " ), time .Now ()})
6667 return true , "" , "" , nil
6768}
@@ -279,13 +280,14 @@ func TestCorrectCommandExecutionWhenApplying(t *testing.T) {
279280 Reporter : reporter ,
280281 PlanStorage : planStorage ,
281282 PlanPathProvider : planPathProvider ,
283+ IacUtils : iac_utils.TerraformUtils {},
282284 }
283285
284286 executor .Apply ()
285287
286288 commandStrings := allCommandsInOrderWithParams (terraformExecutor , commandRunner , prManager , lock , planStorage , planPathProvider )
287289
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 )
289291}
290292
291293func TestCorrectCommandExecutionWhenDestroying (t * testing.T ) {
@@ -368,6 +370,7 @@ func TestCorrectCommandExecutionWhenPlanning(t *testing.T) {
368370 Reporter : reporter ,
369371 PlanStorage : planStorage ,
370372 PlanPathProvider : planPathProvider ,
373+ IacUtils : iac_utils.TerraformUtils {},
371374 }
372375
373376 os .WriteFile (planPathProvider .LocalPlanFilePath (), []byte {123 }, 0644 )
@@ -377,7 +380,7 @@ func TestCorrectCommandExecutionWhenPlanning(t *testing.T) {
377380
378381 commandStrings := allCommandsInOrderWithParams (terraformExecutor , commandRunner , prManager , lock , planStorage , planPathProvider )
379382
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 )
381384}
382385
383386func allCommandsInOrderWithParams (terraformExecutor * MockTerraformExecutor , commandRunner * MockCommandRunner , prManager * MockPRManager , lock * MockProjectLock , planStorage * MockPlanStorage , planPathProvider * MockPlanPathProvider ) []string {
0 commit comments