github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/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 return nil 58 } 59 } 60 61 const testAccCheckScalewayBootscriptConfig = ` 62 data "scaleway_bootscript" "debug" { 63 name = "x86_64 4.8.3 debug #1" 64 } 65 ` 66 67 const testAccCheckScalewayBootscriptFilterConfig = ` 68 data "scaleway_bootscript" "debug" { 69 architecture = "arm" 70 name_filter = "Rescue" 71 } 72 `