github.com/ns1/terraform@v0.7.10-0.20161109153551-8949419bef40/builtin/providers/scaleway/data_source_scaleway_bootscript_test.go (about) 1 package scaleway 2 3 import ( 4 "fmt" 5 "regexp" 6 "testing" 7 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 func TestAccScalewayDataSourceBootscript_Basic(t *testing.T) { 13 resource.Test(t, resource.TestCase{ 14 PreCheck: func() { testAccPreCheck(t) }, 15 Providers: testAccProviders, 16 Steps: []resource.TestStep{ 17 resource.TestStep{ 18 Config: testAccCheckScalewayBootscriptConfig, 19 Check: resource.ComposeTestCheckFunc( 20 testAccCheckBootscriptID("data.scaleway_bootscript.debug"), 21 resource.TestCheckResourceAttr("data.scaleway_bootscript.debug", "architecture", "x86_64"), 22 resource.TestCheckResourceAttr("data.scaleway_bootscript.debug", "public", "true"), 23 resource.TestMatchResourceAttr("data.scaleway_bootscript.debug", "kernel", regexp.MustCompile("4.8.3")), 24 ), 25 }, 26 }, 27 }) 28 } 29 30 func TestAccScalewayDataSourceBootscript_Filtered(t *testing.T) { 31 resource.Test(t, resource.TestCase{ 32 PreCheck: func() { testAccPreCheck(t) }, 33 Providers: testAccProviders, 34 Steps: []resource.TestStep{ 35 resource.TestStep{ 36 Config: testAccCheckScalewayBootscriptFilterConfig, 37 Check: resource.ComposeTestCheckFunc( 38 testAccCheckBootscriptID("data.scaleway_bootscript.debug"), 39 resource.TestCheckResourceAttr("data.scaleway_bootscript.debug", "architecture", "arm"), 40 resource.TestCheckResourceAttr("data.scaleway_bootscript.debug", "public", "true"), 41 ), 42 }, 43 }, 44 }) 45 } 46 47 func testAccCheckBootscriptID(n string) resource.TestCheckFunc { 48 return func(s *terraform.State) error { 49 rs, ok := s.RootModule().Resources[n] 50 if !ok { 51 return fmt.Errorf("Can't find bootscript data source: %s", n) 52 } 53 54 if rs.Primary.ID == "" { 55 return fmt.Errorf("bootscript data source ID not set") 56 } 57 58 scaleway := testAccProvider.Meta().(*Client).scaleway 59 _, err := scaleway.GetBootscript(rs.Primary.ID) 60 if err != nil { 61 return err 62 } 63 64 return nil 65 } 66 } 67 68 const testAccCheckScalewayBootscriptConfig = ` 69 data "scaleway_bootscript" "debug" { 70 name = "x86_64 4.8.3 debug #1" 71 } 72 ` 73 74 const testAccCheckScalewayBootscriptFilterConfig = ` 75 data "scaleway_bootscript" "debug" { 76 architecture = "arm" 77 name_filter = "Rescue" 78 } 79 `