github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/rundeck/resource_project_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 TestAccProject_basic(t *testing.T) { 14 var project rundeck.Project 15 16 resource.Test(t, resource.TestCase{ 17 PreCheck: func() { testAccPreCheck(t) }, 18 Providers: testAccProviders, 19 CheckDestroy: testAccProjectCheckDestroy(&project), 20 Steps: []resource.TestStep{ 21 resource.TestStep{ 22 Config: testAccProjectConfig_basic, 23 Check: resource.ComposeTestCheckFunc( 24 testAccProjectCheckExists("rundeck_project.main", &project), 25 func(s *terraform.State) error { 26 if expected := "terraform-acc-test-basic"; project.Name != expected { 27 return fmt.Errorf("wrong name; expected %v, got %v", expected, project.Name) 28 } 29 if expected := "baz"; project.Config["foo.bar"] != expected { 30 return fmt.Errorf("wrong foo.bar config; expected %v, got %v", expected, project.Config["foo.bar"]) 31 } 32 if expected := "file"; project.Config["resources.source.1.type"] != expected { 33 return fmt.Errorf("wrong resources.source.1.type config; expected %v, got %v", expected, project.Config["resources.source.1.type"]) 34 } 35 return nil 36 }, 37 ), 38 }, 39 }, 40 }) 41 } 42 43 func testAccProjectCheckDestroy(project *rundeck.Project) resource.TestCheckFunc { 44 return func(s *terraform.State) error { 45 client := testAccProvider.Meta().(*rundeck.Client) 46 _, err := client.GetProject(project.Name) 47 if err == nil { 48 return fmt.Errorf("project still exists") 49 } 50 if _, ok := err.(*rundeck.NotFoundError); !ok { 51 return fmt.Errorf("got something other than NotFoundError (%v) when getting project", err) 52 } 53 54 return nil 55 } 56 } 57 58 func testAccProjectCheckExists(rn string, project *rundeck.Project) resource.TestCheckFunc { 59 return func(s *terraform.State) error { 60 rs, ok := s.RootModule().Resources[rn] 61 if !ok { 62 return fmt.Errorf("resource not found: %s", rn) 63 } 64 65 if rs.Primary.ID == "" { 66 return fmt.Errorf("project id not set") 67 } 68 69 client := testAccProvider.Meta().(*rundeck.Client) 70 gotProject, err := client.GetProject(rs.Primary.ID) 71 if err != nil { 72 return fmt.Errorf("error getting project: %s", err) 73 } 74 75 *project = *gotProject 76 77 return nil 78 } 79 } 80 81 const testAccProjectConfig_basic = ` 82 resource "rundeck_project" "main" { 83 name = "terraform-acc-test-basic" 84 description = "Terraform Acceptance Tests Basic Project" 85 86 resource_model_source { 87 type = "file" 88 config = { 89 format = "resourcexml" 90 file = "/tmp/terraform-acc-tests.xml" 91 } 92 } 93 94 extra_config = { 95 "foo/bar" = "baz" 96 } 97 } 98 `