From df87b1a31b106fd6b4edc7d464307ed4fe7472c7 Mon Sep 17 00:00:00 2001 From: Andrea Berlingieri Date: Wed, 26 Jun 2024 15:27:03 +0200 Subject: [PATCH] Fix Acceptance tests Add timeout and success_on_empty_node_filter to attributes set to the job based on job data (jobToResourceData function) Fix TestOchestrator_high_low and TestOchestrator_max_percent (wrong job name in the expected/actual test) Fix testAccJobOptions_secure_options (shouldn't expect an error, should just check that the right option on the job has been set) --- rundeck/import_resource_job_test.go | 2 +- rundeck/resource_job.go | 6 ++++++ rundeck/resource_job_test.go | 23 +++++++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/rundeck/import_resource_job_test.go b/rundeck/import_resource_job_test.go index 16f1a38065..acd626f19e 100644 --- a/rundeck/import_resource_job_test.go +++ b/rundeck/import_resource_job_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccRundeckJob_Import(t *testing.T) { diff --git a/rundeck/resource_job.go b/rundeck/resource_job.go index 95d5e364e8..f4a5e8730e 100644 --- a/rundeck/resource_job.go +++ b/rundeck/resource_job.go @@ -928,6 +928,9 @@ func jobToResourceData(job *JobDetail, d *schema.ResourceData) error { if err := d.Set("allow_concurrent_executions", job.AllowConcurrentExecutions); err != nil { return err } + if err := d.Set("timeout", job.Timeout); err != nil { + return err + } if job.Retry != nil { if err := d.Set("retry", job.Retry.Value); err != nil { return err @@ -949,6 +952,9 @@ func jobToResourceData(job *JobDetail, d *schema.ResourceData) error { if err := d.Set("rank_order", job.Dispatch.RankOrder); err != nil { return err } + if err := d.Set("success_on_empty_node_filter", job.Dispatch.SuccessOnEmptyNodeFilter); err != nil { + return err + } } else { if err := d.Set("max_thread_count", 1); err != nil { return err diff --git a/rundeck/resource_job_test.go b/rundeck/resource_job_test.go index 20fec04586..da647a05f7 100644 --- a/rundeck/resource_job_test.go +++ b/rundeck/resource_job_test.go @@ -83,7 +83,7 @@ func TestOchestrator_high_low(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccJobCheckExists("rundeck_job.test", &job), func(s *terraform.State) error { - if expected := "basic-job-with-node-filter"; job.Name != expected { + if expected := "orchestrator-High-Low"; job.Name != expected { return fmt.Errorf("wrong name; expected %v, got %v", expected, job.Name) } if expected := "name: tacobell"; job.CommandSequence.Commands[0].Job.NodeFilter.Query != expected { @@ -110,7 +110,7 @@ func TestOchestrator_max_percent(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccJobCheckExists("rundeck_job.test", &job), func(s *terraform.State) error { - if expected := "basic-job-with-node-filter"; job.Name != expected { + if expected := "orchestrator-MaxPercent"; job.Name != expected { return fmt.Errorf("wrong name; expected %v, got %v", expected, job.Name) } if expected := "name: tacobell"; job.CommandSequence.Commands[0].Job.NodeFilter.Query != expected { @@ -261,8 +261,23 @@ func TestAccJobOptions_secure_choice(t *testing.T) { CheckDestroy: testAccJobCheckDestroy(&job), Steps: []resource.TestStep{ { - Config: testAccJobOptions_secure_options, - ExpectError: regexp.MustCompile("argument \"value_choices\" can not have empty values; try \"required\""), + Config: testAccJobOptions_secure_options, + Check: resource.ComposeTestCheckFunc( + testAccJobCheckExists("rundeck_job.test", &job), + func(s *terraform.State) error { + secureOption := job.OptionsConfig.Options[0] + if expected := "foo_secure"; secureOption.Name != expected { + return fmt.Errorf("wrong name; expected %v, got %v", expected, secureOption.Name) + } + if expected := "/keys/test/path/"; secureOption.StoragePath != expected { + return fmt.Errorf("wrong storage_path; expected %v, got %v", expected, secureOption.Name) + } + if expected := true; secureOption.ObscureInput != expected { + return fmt.Errorf("failed to set the input as obscure; expected %v, got %v", expected, secureOption.ObscureInput) + } + return nil + }, + ), }, }, })