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