github.com/bradfeehan/terraform@v0.7.0-rc3.0.20170529055808-34b45c5ad841/builtin/providers/ovh/resource_ovh_publiccloud_user_test.go (about) 1 package ovh 2 3 import ( 4 "fmt" 5 "os" 6 "testing" 7 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 var testAccPublicCloudUserConfig = fmt.Sprintf(` 13 resource "ovh_publiccloud_user" "user" { 14 project_id = "%s" 15 description = "my user for acceptance tests" 16 } 17 `, os.Getenv("OVH_PUBLIC_CLOUD")) 18 19 func TestAccPublicCloudUser_basic(t *testing.T) { 20 resource.Test(t, resource.TestCase{ 21 PreCheck: func() { testAccCheckPublicCloudUserPreCheck(t) }, 22 Providers: testAccProviders, 23 CheckDestroy: testAccCheckPublicCloudUserDestroy, 24 Steps: []resource.TestStep{ 25 resource.TestStep{ 26 Config: testAccPublicCloudUserConfig, 27 Check: resource.ComposeTestCheckFunc( 28 testAccCheckPublicCloudUserExists("ovh_publiccloud_user.user", t), 29 testAccCheckPublicCloudUserOpenRC("ovh_publiccloud_user.user", t), 30 ), 31 }, 32 }, 33 }) 34 } 35 36 func testAccCheckPublicCloudUserPreCheck(t *testing.T) { 37 testAccPreCheck(t) 38 testAccCheckPublicCloudExists(t) 39 } 40 41 func testAccCheckPublicCloudUserExists(n string, t *testing.T) resource.TestCheckFunc { 42 return func(s *terraform.State) error { 43 config := testAccProvider.Meta().(*Config) 44 45 rs, ok := s.RootModule().Resources[n] 46 if !ok { 47 return fmt.Errorf("Not found: %s", n) 48 } 49 50 if rs.Primary.ID == "" { 51 return fmt.Errorf("No ID is set") 52 } 53 54 if rs.Primary.Attributes["project_id"] == "" { 55 return fmt.Errorf("No Project ID is set") 56 } 57 58 return publicCloudUserExists(rs.Primary.Attributes["project_id"], rs.Primary.ID, config.OVHClient) 59 } 60 } 61 62 func testAccCheckPublicCloudUserOpenRC(n string, t *testing.T) resource.TestCheckFunc { 63 return func(s *terraform.State) error { 64 rs, ok := s.RootModule().Resources[n] 65 if !ok { 66 return fmt.Errorf("Not found: %s", n) 67 } 68 69 if rs.Primary.ID == "" { 70 return fmt.Errorf("No ID is set") 71 } 72 73 if rs.Primary.Attributes["openstack_rc.OS_AUTH_URL"] == "" { 74 return fmt.Errorf("No openstack_rc.OS_AUTH_URL is set") 75 } 76 77 if rs.Primary.Attributes["openstack_rc.OS_TENANT_ID"] == "" { 78 return fmt.Errorf("No openstack_rc.OS_TENANT_ID is set") 79 } 80 81 if rs.Primary.Attributes["openstack_rc.OS_TENANT_NAME"] == "" { 82 return fmt.Errorf("No openstack_rc.OS_TENANT_NAME is set") 83 } 84 85 if rs.Primary.Attributes["openstack_rc.OS_USERNAME"] == "" { 86 return fmt.Errorf("No openstack_rc.OS_USERNAME is set") 87 } 88 89 return nil 90 } 91 } 92 93 func testAccCheckPublicCloudUserDestroy(s *terraform.State) error { 94 config := testAccProvider.Meta().(*Config) 95 for _, rs := range s.RootModule().Resources { 96 if rs.Type != "ovh_publiccloud_user" { 97 continue 98 } 99 100 err := publicCloudUserExists(rs.Primary.Attributes["project_id"], rs.Primary.ID, config.OVHClient) 101 if err == nil { 102 return fmt.Errorf("VRack > Public Cloud User still exists") 103 } 104 105 } 106 return nil 107 }