github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/opc/resource_image_list_test.go (about)

     1  package opc
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/go-oracle-terraform/compute"
     8  	"github.com/hashicorp/terraform/helper/acctest"
     9  	"github.com/hashicorp/terraform/helper/resource"
    10  	"github.com/hashicorp/terraform/terraform"
    11  )
    12  
    13  func TestAccOPCImageList_Basic(t *testing.T) {
    14  	ri := acctest.RandInt()
    15  	config := fmt.Sprintf(testAccImageList_basic, ri)
    16  
    17  	resource.Test(t, resource.TestCase{
    18  		PreCheck:     func() { testAccPreCheck(t) },
    19  		Providers:    testAccProviders,
    20  		CheckDestroy: testAccCheckImageListDestroy,
    21  		Steps: []resource.TestStep{
    22  			{
    23  				Config: config,
    24  				Check:  testAccCheckImageListExists,
    25  			},
    26  		},
    27  	})
    28  }
    29  
    30  func TestAccOPCImageList_Complete(t *testing.T) {
    31  	ri := acctest.RandInt()
    32  	config := fmt.Sprintf(testAccImageList_complete, ri)
    33  
    34  	resource.Test(t, resource.TestCase{
    35  		PreCheck:     func() { testAccPreCheck(t) },
    36  		Providers:    testAccProviders,
    37  		CheckDestroy: testAccCheckImageListDestroy,
    38  		Steps: []resource.TestStep{
    39  			{
    40  				Config: config,
    41  				Check:  testAccCheckImageListExists,
    42  			},
    43  		},
    44  	})
    45  }
    46  
    47  func testAccCheckImageListExists(s *terraform.State) error {
    48  	client := testAccProvider.Meta().(*compute.Client).ImageList()
    49  
    50  	for _, rs := range s.RootModule().Resources {
    51  		if rs.Type != "opc_compute_image_list" {
    52  			continue
    53  		}
    54  
    55  		input := compute.GetImageListInput{
    56  			Name: rs.Primary.Attributes["name"],
    57  		}
    58  		if _, err := client.GetImageList(&input); err != nil {
    59  			return fmt.Errorf("Error retrieving state of Image List %s: %s", input.Name, err)
    60  		}
    61  	}
    62  
    63  	return nil
    64  }
    65  
    66  func testAccCheckImageListDestroy(s *terraform.State) error {
    67  	client := testAccProvider.Meta().(*compute.Client).ImageList()
    68  
    69  	for _, rs := range s.RootModule().Resources {
    70  		if rs.Type != "opc_compute_image_list" {
    71  			continue
    72  		}
    73  
    74  		input := compute.GetImageListInput{
    75  			Name: rs.Primary.Attributes["name"],
    76  		}
    77  		if info, err := client.GetImageList(&input); err == nil {
    78  			return fmt.Errorf("Image List %s still exists: %#v", input.Name, info)
    79  		}
    80  	}
    81  
    82  	return nil
    83  }
    84  
    85  var testAccImageList_basic = `
    86  resource "opc_compute_image_list" "test" {
    87    name        = "test-acc-image-list-basic-%d"
    88    description = "Image List (Basic)"
    89  }
    90  `
    91  
    92  var testAccImageList_complete = `
    93  resource "opc_compute_image_list" "test" {
    94    name        = "test-acc-image-list-complete-%d"
    95    description = "Image List (Complete)"
    96    default     = 2
    97  }
    98  `