github.com/richardbowden/terraform@v0.6.12-0.20160901200758-30ea22c25211/builtin/providers/azure/resource_azure_storage_queue_test.go (about) 1 package azure 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func TestAccAzureStorageQueue(t *testing.T) { 12 name := "azure_storage_queue.foo" 13 14 resource.Test(t, resource.TestCase{ 15 PreCheck: func() { testAccPreCheck(t) }, 16 Providers: testAccProviders, 17 CheckDestroy: testAccCheckAzureStorageQueueDeleted, 18 Steps: []resource.TestStep{ 19 resource.TestStep{ 20 Config: testAccAzureStorageQueueConfig, 21 Check: resource.ComposeTestCheckFunc( 22 testAccCheckAzureStorageQueueExists(name), 23 resource.TestCheckResourceAttr(name, "name", "terraform-queue"), 24 resource.TestCheckResourceAttr(name, "storage_service_name", testAccStorageServiceName), 25 ), 26 }, 27 }, 28 }) 29 } 30 31 func testAccCheckAzureStorageQueueExists(name string) resource.TestCheckFunc { 32 return func(s *terraform.State) error { 33 resource, ok := s.RootModule().Resources[name] 34 if !ok { 35 return fmt.Errorf("Azure Storage Queue resource '%s' is missing.", name) 36 } 37 38 if resource.Primary.ID == "" { 39 return fmt.Errorf("Azure Storage Service Queue ID %s is missing.", name) 40 } 41 42 azureClient := testAccProvider.Meta().(*Client) 43 queueClient, err := azureClient.getStorageServiceQueueClient(testAccStorageServiceName) 44 if err != nil { 45 return err 46 } 47 48 exists, err := queueClient.QueueExists(resource.Primary.ID) 49 if err != nil { 50 return fmt.Errorf("Error querying Azure for Storage Queue existence: %s", err) 51 } 52 if !exists { 53 return fmt.Errorf("Azure Storage Queue %s doesn't exist!", resource.Primary.ID) 54 } 55 56 return nil 57 } 58 } 59 60 func testAccCheckAzureStorageQueueDeleted(s *terraform.State) error { 61 for _, resource := range s.RootModule().Resources { 62 if resource.Type != "azure_storage_queue" { 63 continue 64 } 65 66 if resource.Primary.ID == "" { 67 return fmt.Errorf("Azure Storage Service Queue ID %s is missing.", resource.Primary.ID) 68 } 69 70 azureClient := testAccProvider.Meta().(*Client) 71 queueClient, err := azureClient.getStorageServiceQueueClient(testAccStorageServiceName) 72 if err != nil { 73 return err 74 } 75 76 exists, err := queueClient.QueueExists(resource.Primary.ID) 77 if err != nil { 78 return fmt.Errorf("Error querying Azure for Storage Queue existence: %s", err) 79 } 80 if exists { 81 return fmt.Errorf("Azure Storage Queue %s still exists!", resource.Primary.ID) 82 } 83 } 84 85 return nil 86 } 87 88 var testAccAzureStorageQueueConfig = fmt.Sprintf(` 89 resource "azure_storage_queue" "foo" { 90 name = "terraform-queue" 91 storage_service_name = "%s" 92 } 93 `, testAccStorageServiceName)