Skip to content

Commit

Permalink
Merge pull request scaleway#100 from terraform-providers/fix-tests
Browse files Browse the repository at this point in the history
fix tests
  • Loading branch information
nicolai86 authored Nov 20, 2018
2 parents e275113 + 0bed425 commit 8aaee93
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 94 deletions.
2 changes: 1 addition & 1 deletion scaleway/data_source_bootscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ func testAccCheckBootscriptID(n string) resource.TestCheckFunc {
const testAccCheckScalewayBootscriptFilterConfig = `
data "scaleway_bootscript" "debug" {
architecture = "arm"
name_filter = "Rescue"
name_filter = "rescue"
}
`
16 changes: 11 additions & 5 deletions scaleway/resource_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,21 @@ resource "scaleway_ip" "base" {
}
`

var testAccCheckScalewayIPAttachConfig = fmt.Sprintf(`
var testAccCheckScalewayIPAttachConfig = `
data "scaleway_image" "ubuntu" {
architecture = "arm64"
name = "Ubuntu Xenial"
most_recent = true
}
resource "scaleway_server" "base" {
name = "test"
# ubuntu 14.04
image = "%s"
type = "C1"
image = "${data.scaleway_image.ubuntu.id}"
type = "ARM64-2GB"
}
resource "scaleway_ip" "base" {
server = "${scaleway_server.base.id}"
}
`, armImageIdentifier)
`
6 changes: 3 additions & 3 deletions scaleway/resource_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
api "github.com/nicolai86/scaleway-sdk"
)

var supportedDefaultTrafficPolicies = []string{"accept", "drop"}
var supportedDefaultTrafficPolicies = []string{"accept", "drop", ""}

func resourceScalewaySecurityGroup() *schema.Resource {
return &schema.Resource{
Expand Down Expand Up @@ -40,14 +40,14 @@ func resourceScalewaySecurityGroup() *schema.Resource {
"inbound_default_policy": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Default: "accept",
Description: "Default inbound traffic policy for this security group",
ValidateFunc: validation.StringInSlice(supportedDefaultTrafficPolicies, true),
},
"outbound_default_policy": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Default: "accept",
Description: "Default outbound traffic policy for this security group",
ValidateFunc: validation.StringInSlice(supportedDefaultTrafficPolicies, true),
},
Expand Down
6 changes: 3 additions & 3 deletions scaleway/resource_security_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func TestAccScalewaySecurityGroup_Stateful(t *testing.T) {
Config: testAccCheckScalewaySecurityGroupConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewaySecurityGroupExists("scaleway_security_group.base"),
resource.TestCheckResourceAttr("scaleway_security_group.base", "inbound_default_policy", "accept"),
resource.TestCheckResourceAttr("scaleway_security_group.base", "outbound_default_policy", "drop"),
resource.TestCheckResourceAttr("scaleway_security_group.base", "stateful", "false"),
resource.TestCheckResourceAttr("scaleway_security_group.base", "inbound_default_policy", "accept"),
resource.TestCheckResourceAttr("scaleway_security_group.base", "outbound_default_policy", "accept"),
),
},
},
Expand Down Expand Up @@ -170,7 +170,7 @@ var testAccCheckScalewaySecurityGroupConfig_Stateful = `
resource "scaleway_security_group" "base" {
name = "public"
description = "public gateway"
stateful = true
stateful = true
inbound_default_policy = "accept"
outbound_default_policy = "drop"
}
Expand Down
146 changes: 74 additions & 72 deletions scaleway/resource_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ func TestAccScalewayServer_Basic(t *testing.T) {
Config: testAccCheckScalewayServerConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayServerExists("scaleway_server.base"),
testAccCheckScalewayServerAttributes("scaleway_server.base"),
resource.TestCheckResourceAttr(
"scaleway_server.base", "type", "C1"),
"scaleway_server.base", "type", "ARM64-2GB"),
resource.TestCheckResourceAttr(
"scaleway_server.base", "name", "test"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -136,9 +135,8 @@ func TestAccScalewayServer_Volumes(t *testing.T) {
Config: testAccCheckScalewayServerVolumeConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayServerExists("scaleway_server.base"),
testAccCheckScalewayServerAttributes("scaleway_server.base"),
resource.TestCheckResourceAttr(
"scaleway_server.base", "type", "C1"),
"scaleway_server.base", "type", "C2S"),
resource.TestCheckResourceAttr(
"scaleway_server.base", "volume.#", "3"),
resource.TestCheckResourceAttrSet(
Expand Down Expand Up @@ -251,34 +249,6 @@ func testAccCheckScalewayServerIPDetachmentAttributes(n string) resource.TestChe
}
}

func testAccCheckScalewayServerAttributes(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Unknown resource: %s", n)
}

client := testAccProvider.Meta().(*Client).scaleway
server, err := client.GetServer(rs.Primary.ID)

if err != nil {
return err
}

if server.Name != "test" {
return fmt.Errorf("Server has wrong name")
}
if server.Image.Identifier != armImageIdentifier {
return fmt.Errorf("Wrong server image")
}
if server.CommercialType != "C1" {
return fmt.Errorf("Wrong server type")
}

return nil
}
}

func testAccCheckScalewayServerSecurityGroup(n, securityGroupName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -332,74 +302,97 @@ func testAccCheckScalewayServerExists(n string) resource.TestCheckFunc {
}
}

var armImageIdentifier = "5faef9cd-ea9b-4a63-9171-9e26bec03dbc"
var x86_64ImageIdentifier = "e20532c4-1fa0-4c97-992f-436b8d372c07"

var testAccCheckScalewayServerConfig_dataSource = `
data "scaleway_image" "ubuntu" {
architecture = "arm"
architecture = "arm64"
name = "Ubuntu Xenial"
}
resource "scaleway_server" "base" {
name = "test"
image = "${data.scaleway_image.ubuntu.id}"
type = "C1"
type = "ARM64-2GB"
tags = [ "terraform-test", "xenial" ]
}`

var testAccCheckScalewayServerConfig = fmt.Sprintf(`
var testAccCheckScalewayServerConfig = `
data "scaleway_image" "ubuntu" {
architecture = "arm64"
name = "Ubuntu Xenial"
most_recent = true
}
resource "scaleway_server" "base" {
name = "test"
# ubuntu 14.04
image = "%s"
type = "C1"
image = "${data.scaleway_image.ubuntu.id}"
type = "ARM64-2GB"
tags = [ "terraform-test" ]
cloudinit = <<EOF
#cloud-config
apt_update: true
apt_upgrade: true
EOF
}`, armImageIdentifier)
}`

var testAccCheckScalewayServerConfig_LocalBoot = `
data "scaleway_image" "ubuntu" {
architecture = "x86_64"
name = "Ubuntu Xenial"
most_recent = true
}
var testAccCheckScalewayServerConfig_LocalBoot = fmt.Sprintf(`
resource "scaleway_server" "base" {
name = "test"
# ubuntu 14.04
image = "%s"
type = "VC1S"
image = "${data.scaleway_image.ubuntu.id}"
type = "START1-S"
tags = [ "terraform-test", "local_boot" ]
boot_type = "local"
}`, x86_64ImageIdentifier)
}`

var testAccCheckScalewayServerConfig_IPAttachment = `
data "scaleway_image" "ubuntu" {
architecture = "arm64"
name = "Ubuntu Xenial"
most_recent = true
}
var testAccCheckScalewayServerConfig_IPAttachment = fmt.Sprintf(`
resource "scaleway_ip" "base" {}
resource "scaleway_server" "base" {
name = "test"
# ubuntu 14.04
image = "%s"
type = "C1"
image = "${data.scaleway_image.ubuntu.id}"
type = "ARM64-2GB"
tags = [ "terraform-test", "scaleway_ip" ]
public_ip = "${scaleway_ip.base.ip}"
}`, armImageIdentifier)
}`

var testAccCheckScalewayServerConfig_IPDetachment = `
data "scaleway_image" "ubuntu" {
architecture = "arm64"
most_recent = true
name = "Ubuntu Xenial"
}
var testAccCheckScalewayServerConfig_IPDetachment = fmt.Sprintf(`
resource "scaleway_server" "base" {
name = "test"
# ubuntu 14.04
image = "%s"
type = "C1"
image = "${data.scaleway_image.ubuntu.id}"
type = "ARM64-2GB"
tags = [ "terraform-test" ]
}`, armImageIdentifier)
}
`

var testAccCheckScalewayServerVolumeConfig = `
data "scaleway_image" "ubuntu" {
architecture = "x86_64"
name = "Ubuntu Xenial"
most_recent = true
}
var testAccCheckScalewayServerVolumeConfig = fmt.Sprintf(`
resource "scaleway_server" "base" {
name = "test"
# ubuntu 14.04
image = "%s"
type = "C1"
image = "${data.scaleway_image.ubuntu.id}"
type = "C2S"
tags = [ "terraform-test", "inline-images" ]
volume {
Expand All @@ -416,9 +409,14 @@ resource "scaleway_server" "base" {
size_in_gb = 30
type = "l_ssd"
}
}`, armImageIdentifier)
}`

var testAccCheckScalewayServerConfig_SecurityGroup = `
data "scaleway_image" "ubuntu" {
architecture = "arm64"
name = "Ubuntu Xenial"
}
var testAccCheckScalewayServerConfig_SecurityGroup = fmt.Sprintf(`
resource "scaleway_security_group" "blue" {
name = "blue"
description = "blue"
Expand All @@ -431,14 +429,19 @@ resource "scaleway_security_group" "red" {
resource "scaleway_server" "base" {
name = "test"
# ubuntu 14.04
image = "%s"
type = "C1"
image = "${data.scaleway_image.ubuntu.id}"
type = "ARM64-2GB"
tags = [ "terraform-test", "security_groups.blue" ]
security_group = "${scaleway_security_group.blue.id}"
}`, armImageIdentifier)
}`

var testAccCheckScalewayServerConfig_SecurityGroup_Update = `
data "scaleway_image" "ubuntu" {
architecture = "arm64"
name = "Ubuntu Xenial"
most_recent = true
}
var testAccCheckScalewayServerConfig_SecurityGroup_Update = fmt.Sprintf(`
resource "scaleway_security_group" "blue" {
name = "blue"
description = "blue"
Expand All @@ -451,9 +454,8 @@ resource "scaleway_security_group" "red" {
resource "scaleway_server" "base" {
name = "test"
# ubuntu 14.04
image = "%s"
type = "C1"
image = "${data.scaleway_image.ubuntu.id}"
type = "ARM64-2GB"
tags = [ "terraform-test", "security_groups.red" ]
security_group = "${scaleway_security_group.red.id}"
}`, armImageIdentifier)
}`
16 changes: 11 additions & 5 deletions scaleway/resource_user_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ func testAccCheckScalewayUserDataDestroy(s *terraform.State) error {
return nil
}

var testAccCheckScalewayUserDataConfig = fmt.Sprintf(`
var testAccCheckScalewayUserDataConfig = `
data "scaleway_image" "ubuntu" {
architecture = "arm64"
name = "Ubuntu Xenial"
most_recent = true
}
resource "scaleway_server" "base" {
name = "test"
# ubuntu 14.04
image = "%s"
type = "C1"
image = "${data.scaleway_image.ubuntu.id}"
type = "ARM64-2GB"
tags = [ "terraform-test", "user-data" ]
}
Expand All @@ -79,4 +85,4 @@ resource "scaleway_user_data" "base" {
key = "gcp_username"
value = "supersecret"
}
`, armImageIdentifier)
`
14 changes: 9 additions & 5 deletions scaleway/resource_volume_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ func testAccCheckScalewayVolumeAttachmentExists(n string) resource.TestCheckFunc
}
}

var testAccCheckScalewayVolumeAttachmentConfig = fmt.Sprintf(`
var testAccCheckScalewayVolumeAttachmentConfig = `
data "scaleway_image" "ubuntu" {
name = "Ubuntu Xenial"
architecture = "x86_64"
}
resource "scaleway_server" "base" {
name = "test"
# ubuntu 14.04
image = "%s"
type = "C1"
image = "${data.scaleway_image.ubuntu.id}"
type = "C2S"
tags = [ "terraform-test", "external-volume-attachment" ]
}
Expand All @@ -90,4 +94,4 @@ resource "scaleway_volume" "test" {
resource "scaleway_volume_attachment" "test" {
server = "${scaleway_server.base.id}"
volume = "${scaleway_volume.test.id}"
}`, armImageIdentifier)
}`

0 comments on commit 8aaee93

Please sign in to comment.