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.
This commit is contained in:
Raphael Randschau 2017-01-17 13:05:16 +01:00 committed by Paul Stack
parent 4fd9012a11
commit 1e589f589c
2 changed files with 6 additions and 27 deletions

View File

@ -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

View File

@ -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"