github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/scaleway/data_source_scaleway_bootscript_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 TestAccScalewayDataSourceBootscript_Filtered(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: testAccCheckScalewayBootscriptFilterConfig,
    18  				Check: resource.ComposeTestCheckFunc(
    19  					testAccCheckBootscriptID("data.scaleway_bootscript.debug"),
    20  					resource.TestCheckResourceAttr("data.scaleway_bootscript.debug", "architecture", "arm"),
    21  					resource.TestCheckResourceAttr("data.scaleway_bootscript.debug", "public", "true"),
    22  				),
    23  			},
    24  		},
    25  	})
    26  }
    27  
    28  func testAccCheckBootscriptID(n string) resource.TestCheckFunc {
    29  	return func(s *terraform.State) error {
    30  		rs, ok := s.RootModule().Resources[n]
    31  		if !ok {
    32  			return fmt.Errorf("Can't find bootscript data source: %s", n)
    33  		}
    34  
    35  		if rs.Primary.ID == "" {
    36  			return fmt.Errorf("bootscript data source ID not set")
    37  		}
    38  
    39  		scaleway := testAccProvider.Meta().(*Client).scaleway
    40  		_, err := scaleway.GetBootscript(rs.Primary.ID)
    41  		if err != nil {
    42  			return err
    43  		}
    44  
    45  		return nil
    46  	}
    47  }
    48  
    49  const testAccCheckScalewayBootscriptFilterConfig = `
    50  data "scaleway_bootscript" "debug" {
    51    architecture = "arm"
    52    name_filter = "Rescue"
    53  }
    54  `