From 1e589f589cc2b09b5baaf18b7724ce419ea364d5 Mon Sep 17 00:00:00 2001 From: Raphael Randschau Date: Tue, 17 Jan 2017 13:05:16 +0100 Subject: [PATCH] provider/scaleway improve bootscript data source (#11183) * provider/scaleway: fix bootscript tests the bootscript tests where failing because the referenced bootscript is no longer available. for now this just makes the tests pass again, next step should be to lookup a bootscript so we don't have to update the tests all the time * provider/scaleway: fix bootscript data source filter bug when providing a name only the architecture was ignoerd, which can lead to issues since some bootscript names are identical, even though the architecture is different. * provider/scaleway: remove data bootscript exact name test the test fails after some time because scaleway removes older bootscripts. let's just settle with filtered tests for now, which don't have this problem. --- .../data_source_scaleway_bootscript.go | 8 ++++-- .../data_source_scaleway_bootscript_test.go | 25 ------------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/builtin/providers/scaleway/data_source_scaleway_bootscript.go b/builtin/providers/scaleway/data_source_scaleway_bootscript.go index 3c2a6a275..63232bfda 100644 --- a/builtin/providers/scaleway/data_source_scaleway_bootscript.go +++ b/builtin/providers/scaleway/data_source_scaleway_bootscript.go @@ -80,12 +80,16 @@ func dataSourceScalewayBootscriptRead(d *schema.ResourceData, meta interface{}) var isMatch func(api.ScalewayBootscript) bool + architecture := d.Get("architecture") if name, ok := d.GetOk("name"); ok { isMatch = func(s api.ScalewayBootscript) bool { - return s.Title == name.(string) + architectureMatch := true + if architecture != "" { + architectureMatch = architecture == s.Arch + } + return s.Title == name.(string) && architectureMatch } } else if nameFilter, ok := d.GetOk("name_filter"); ok { - architecture := d.Get("architecture") exp, err := regexp.Compile(nameFilter.(string)) if err != nil { return err diff --git a/builtin/providers/scaleway/data_source_scaleway_bootscript_test.go b/builtin/providers/scaleway/data_source_scaleway_bootscript_test.go index 7c5ee3a5e..3c0c10696 100644 --- a/builtin/providers/scaleway/data_source_scaleway_bootscript_test.go +++ b/builtin/providers/scaleway/data_source_scaleway_bootscript_test.go @@ -2,31 +2,12 @@ package scaleway import ( "fmt" - "regexp" "testing" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) -func TestAccScalewayDataSourceBootscript_Basic(t *testing.T) { - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccCheckScalewayBootscriptConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckBootscriptID("data.scaleway_bootscript.debug"), - resource.TestCheckResourceAttr("data.scaleway_bootscript.debug", "architecture", "x86_64"), - resource.TestCheckResourceAttr("data.scaleway_bootscript.debug", "public", "true"), - resource.TestMatchResourceAttr("data.scaleway_bootscript.debug", "kernel", regexp.MustCompile("4.8.3")), - ), - }, - }, - }) -} - func TestAccScalewayDataSourceBootscript_Filtered(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -65,12 +46,6 @@ func testAccCheckBootscriptID(n string) resource.TestCheckFunc { } } -const testAccCheckScalewayBootscriptConfig = ` -data "scaleway_bootscript" "debug" { - name = "x86_64 4.8.3 debug #1" -} -` - const testAccCheckScalewayBootscriptFilterConfig = ` data "scaleway_bootscript" "debug" { architecture = "arm"