From 9d16a9a402a604a18955b4d44f51463406909858 Mon Sep 17 00:00:00 2001 From: Olivier CANO Date: Wed, 4 Dec 2019 16:14:51 +0100 Subject: [PATCH] add tests --- scaleway/data_source_instance_image_test.go | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 scaleway/data_source_instance_image_test.go diff --git a/scaleway/data_source_instance_image_test.go b/scaleway/data_source_instance_image_test.go new file mode 100644 index 000000000..be516aaf4 --- /dev/null +++ b/scaleway/data_source_instance_image_test.go @@ -0,0 +1,72 @@ +package scaleway + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/scaleway/scaleway-sdk-go/api/instance/v1" +) + +func TestAccScalewayDataSourceInstanceImage_Basic(t *testing.T) { + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: ` +data "scaleway_instance_image" "prod" { + name = "golang 1.10" +} + +data "scaleway_instance_image" "stg" { + image_id = "43213956-c7a3-44b8-9d96-d51fa7457969" +}`, + Check: resource.ComposeTestCheckFunc( + testAccCheckScalewayInstanceImageExists("data.scaleway_instance_image.prod"), + resource.TestCheckResourceAttr("data.scaleway_instance_image.prod", "name", "Golang 1.10"), + testAccCheckScalewayInstanceImageExists("data.scaleway_instance_image.stg"), + resource.TestCheckResourceAttr("data.scaleway_instance_image.stg", "name", "Golang 1.10"), + resource.TestCheckResourceAttr("data.scaleway_instance_image.stg", "architecture", "x86_64"), + resource.TestCheckResourceAttr("data.scaleway_instance_image.stg", "creation_date", "2018-04-12T10:22:46Z"), + resource.TestCheckResourceAttr("data.scaleway_instance_image.stg", "modification_date", "2018-04-12T15:02:26Z"), + resource.TestCheckResourceAttr("data.scaleway_instance_image.stg", "public", "true"), + resource.TestCheckResourceAttr("data.scaleway_instance_image.stg", "from_server_id", ""), + resource.TestCheckResourceAttr("data.scaleway_instance_image.stg", "state", "available"), + resource.TestCheckResourceAttr("data.scaleway_instance_image.stg", "bootscript_id", "b1e68c26-a19c-4eac-9222-498b22bd7ad9"), + resource.TestCheckResourceAttr("data.scaleway_instance_image.stg", "root_volume_id", "8fa97c03-ca3b-4267-ba19-2d38190b1c82"), + resource.TestCheckNoResourceAttr("data.scaleway_instance_image.stg", "additional_volume_ids"), + ), + }, + }, + }) +} + +func testAccCheckScalewayInstanceImageExists(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + + if !ok { + return fmt.Errorf("not found: %s", n) + } + + zone, ID, err := parseZonedID(rs.Primary.ID) + if err != nil { + return err + } + + meta := testAccProvider.Meta().(*Meta) + instanceApi := instance.NewAPI(meta.scwClient) + _, err = instanceApi.GetImage(&instance.GetImageRequest{ + ImageID: ID, + Zone: zone, + }) + + if err != nil { + return err + } + + return nil + } +}