github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/scaleway/data_source_scaleway_image_test.go (about)

     1  package scaleway
     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 TestAccScalewayDataSourceImage_Basic(t *testing.T) {
    12  	resource.Test(t, resource.TestCase{
    13  		PreCheck:  func() { testAccPreCheck(t) },
    14  		Providers: testAccProviders,
    15  		Steps: []resource.TestStep{
    16  			resource.TestStep{
    17  				Config: testAccCheckScalewayImageConfig,
    18  				Check: resource.ComposeTestCheckFunc(
    19  					testAccCheckImageID("data.scaleway_image.ubuntu"),
    20  					resource.TestCheckResourceAttr("data.scaleway_image.ubuntu", "architecture", "arm"),
    21  					resource.TestCheckResourceAttr("data.scaleway_image.ubuntu", "public", "true"),
    22  				),
    23  			},
    24  		},
    25  	})
    26  }
    27  
    28  func TestAccScalewayDataSourceImage_Filtered(t *testing.T) {
    29  	resource.Test(t, resource.TestCase{
    30  		PreCheck:  func() { testAccPreCheck(t) },
    31  		Providers: testAccProviders,
    32  		Steps: []resource.TestStep{
    33  			resource.TestStep{
    34  				Config: testAccCheckScalewayImageFilterConfig,
    35  				Check: resource.ComposeTestCheckFunc(
    36  					testAccCheckImageID("data.scaleway_image.ubuntu"),
    37  					resource.TestCheckResourceAttr("data.scaleway_image.ubuntu", "name", "Ubuntu Precise"),
    38  					resource.TestCheckResourceAttr("data.scaleway_image.ubuntu", "architecture", "arm"),
    39  					resource.TestCheckResourceAttr("data.scaleway_image.ubuntu", "public", "true"),
    40  				),
    41  			},
    42  		},
    43  	})
    44  }
    45  
    46  func testAccCheckImageID(n string) resource.TestCheckFunc {
    47  	return func(s *terraform.State) error {
    48  		rs, ok := s.RootModule().Resources[n]
    49  		if !ok {
    50  			return fmt.Errorf("Can't find image data source: %s", n)
    51  		}
    52  
    53  		if rs.Primary.ID == "" {
    54  			return fmt.Errorf("image data source ID not set")
    55  		}
    56  		return nil
    57  	}
    58  }
    59  
    60  const testAccCheckScalewayImageConfig = `
    61  data "scaleway_image" "ubuntu" {
    62    name = "Ubuntu Precise"
    63    architecture = "arm"
    64  }
    65  `
    66  
    67  const testAccCheckScalewayImageFilterConfig = `
    68  data "scaleway_image" "ubuntu" {
    69    name_filter = "Precise"
    70    architecture = "arm"
    71  }
    72  `