github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/openstack/resource_openstack_objectstorage_container_v1_test.go (about) 1 package openstack 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/containers" 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 func TestAccObjectStorageV1Container_basic(t *testing.T) { 13 resource.Test(t, resource.TestCase{ 14 PreCheck: func() { testAccPreCheck(t) }, 15 Providers: testAccProviders, 16 CheckDestroy: testAccCheckObjectStorageV1ContainerDestroy, 17 Steps: []resource.TestStep{ 18 resource.TestStep{ 19 Config: testAccObjectStorageV1Container_basic, 20 Check: resource.ComposeTestCheckFunc( 21 resource.TestCheckResourceAttr( 22 "openstack_objectstorage_container_v1.container_1", "name", "container_1"), 23 resource.TestCheckResourceAttr( 24 "openstack_objectstorage_container_v1.container_1", "content_type", "application/json"), 25 ), 26 }, 27 resource.TestStep{ 28 Config: testAccObjectStorageV1Container_update, 29 Check: resource.ComposeTestCheckFunc( 30 resource.TestCheckResourceAttr( 31 "openstack_objectstorage_container_v1.container_1", "content_type", "text/plain"), 32 ), 33 }, 34 }, 35 }) 36 } 37 38 func testAccCheckObjectStorageV1ContainerDestroy(s *terraform.State) error { 39 config := testAccProvider.Meta().(*Config) 40 objectStorageClient, err := config.objectStorageV1Client(OS_REGION_NAME) 41 if err != nil { 42 return fmt.Errorf("Error creating OpenStack object storage client: %s", err) 43 } 44 45 for _, rs := range s.RootModule().Resources { 46 if rs.Type != "openstack_objectstorage_container_v1" { 47 continue 48 } 49 50 _, err := containers.Get(objectStorageClient, rs.Primary.ID).Extract() 51 if err == nil { 52 return fmt.Errorf("Container still exists") 53 } 54 } 55 56 return nil 57 } 58 59 const testAccObjectStorageV1Container_basic = ` 60 resource "openstack_objectstorage_container_v1" "container_1" { 61 name = "container_1" 62 metadata { 63 test = "true" 64 } 65 content_type = "application/json" 66 } 67 ` 68 69 const testAccObjectStorageV1Container_update = ` 70 resource "openstack_objectstorage_container_v1" "container_1" { 71 name = "container_1" 72 metadata { 73 test = "true" 74 } 75 content_type = "text/plain" 76 } 77 `