From 18d6ae6cc83fda9d2d7b91407cf2126cbc1b8c5d Mon Sep 17 00:00:00 2001 From: Laure-di Date: Wed, 15 Jan 2025 15:31:55 +0100 Subject: [PATCH] add tests --- internal/services/applesilicon/server_test.go | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/internal/services/applesilicon/server_test.go b/internal/services/applesilicon/server_test.go index 70fe57129..0062e54ed 100644 --- a/internal/services/applesilicon/server_test.go +++ b/internal/services/applesilicon/server_test.go @@ -13,7 +13,7 @@ import ( ) func TestAccServer_Basic(t *testing.T) { - t.Skip("Skipping AppleSilicon test as this kind of server can't be deleted before 24h") + t.Skip("Skipping AppleSilicon deletion before 24h") tt := acctest.NewTestTools(t) defer tt.Cleanup() resource.ParallelTest(t, resource.TestCase{ @@ -25,7 +25,7 @@ func TestAccServer_Basic(t *testing.T) { Config: ` resource scaleway_apple_silicon_server main { name = "test-m1" - type = "M1-M" + type = "M2-M" } `, Check: resource.ComposeTestCheckFunc( @@ -43,6 +43,59 @@ func TestAccServer_Basic(t *testing.T) { }) } +func TestAccServer_EnableVPC(t *testing.T) { + t.Skip("Skipping AppleSilicon VPC not available") + tt := acctest.NewTestTools(t) + defer tt.Cleanup() + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ProviderFactories: tt.ProviderFactories, + CheckDestroy: isServerDestroyed(tt), + Steps: []resource.TestStep{ + { + Config: ` + resource scaleway_apple_silicon_server main { + name = "test-m1" + type = "M2-M" + enable_vpc = true + } + `, + Check: resource.ComposeTestCheckFunc( + isServerPresent(tt, "scaleway_apple_silicon_server.main"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "name", "test-m1"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "type", "M1-M"), + // Computed + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "ip"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "vnc_url"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "created_at"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "deletable_at"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "vpc_status", "vpc_enabled"), + ), + }, + { + Config: ` + resource scaleway_apple_silicon_server main { + name = "test-m1" + type = "M2-M" + enable_vpc = false + } + `, + Check: resource.ComposeTestCheckFunc( + isServerPresent(tt, "scaleway_apple_silicon_server.main"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "name", "test-m1"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "type", "M1-M"), + // Computed + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "ip"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "vnc_url"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "created_at"), + resource.TestCheckResourceAttrSet("scaleway_apple_silicon_server.main", "deletable_at"), + resource.TestCheckResourceAttr("scaleway_apple_silicon_server.main", "vpc_status", "vpc_disabled"), + ), + }, + }, + }) +} + func isServerPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n]