github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/rundeck/resource_job_test.go (about) 1 package rundeck 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/apparentlymart/go-rundeck-api/rundeck" 8 9 "github.com/hashicorp/terraform/helper/resource" 10 "github.com/hashicorp/terraform/terraform" 11 ) 12 13 func TestAccJob_basic(t *testing.T) { 14 var job rundeck.JobDetail 15 16 resource.Test(t, resource.TestCase{ 17 PreCheck: func() { testAccPreCheck(t) }, 18 Providers: testAccProviders, 19 CheckDestroy: testAccJobCheckDestroy(&job), 20 Steps: []resource.TestStep{ 21 resource.TestStep{ 22 Config: testAccJobConfig_basic, 23 Check: resource.ComposeTestCheckFunc( 24 testAccJobCheckExists("rundeck_job.test", &job), 25 func(s *terraform.State) error { 26 if expected := "basic-job"; job.Name != expected { 27 return fmt.Errorf("wrong name; expected %v, got %v", expected, job.Name) 28 } 29 return nil 30 }, 31 ), 32 }, 33 }, 34 }) 35 } 36 37 func testAccJobCheckDestroy(job *rundeck.JobDetail) resource.TestCheckFunc { 38 return func(s *terraform.State) error { 39 client := testAccProvider.Meta().(*rundeck.Client) 40 _, err := client.GetJob(job.ID) 41 if err == nil { 42 return fmt.Errorf("key still exists") 43 } 44 if _, ok := err.(*rundeck.NotFoundError); !ok { 45 return fmt.Errorf("got something other than NotFoundError (%v) when getting key", err) 46 } 47 48 return nil 49 } 50 } 51 52 func testAccJobCheckExists(rn string, job *rundeck.JobDetail) resource.TestCheckFunc { 53 return func(s *terraform.State) error { 54 rs, ok := s.RootModule().Resources[rn] 55 if !ok { 56 return fmt.Errorf("resource not found: %s", rn) 57 } 58 59 if rs.Primary.ID == "" { 60 return fmt.Errorf("job id not set") 61 } 62 63 client := testAccProvider.Meta().(*rundeck.Client) 64 gotJob, err := client.GetJob(rs.Primary.ID) 65 if err != nil { 66 return fmt.Errorf("error getting job details: %s", err) 67 } 68 69 *job = *gotJob 70 71 return nil 72 } 73 } 74 75 const testAccJobConfig_basic = ` 76 resource "rundeck_project" "test" { 77 name = "terraform-acc-test-job" 78 description = "parent project for job acceptance tests" 79 resource_model_source { 80 type = "file" 81 config = { 82 format = "resourcexml" 83 file = "/tmp/terraform-acc-tests.xml" 84 } 85 } 86 } 87 resource "rundeck_job" "test" { 88 project_name = "${rundeck_project.test.name}" 89 name = "basic-job" 90 description = "A basic job" 91 node_filter_query = "example" 92 allow_concurrent_executions = 1 93 max_thread_count = 1 94 rank_order = "ascending" 95 schedule = "0 0 12 * * * *" 96 option { 97 name = "foo" 98 default_value = "bar" 99 } 100 command { 101 shell_command = "echo Hello World" 102 } 103 } 104 `