Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Laure-di committed Jan 15, 2025
1 parent 82860c4 commit dc845a8
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions internal/services/applesilicon/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

func TestAccServer_Basic(t *testing.T) {
t.Skip("Skipping AppleSilicon test as this kind of server can't be deleted before 24h")
tt := acctest.NewTestTools(t)
defer tt.Cleanup()
resource.ParallelTest(t, resource.TestCase{
Expand All @@ -25,7 +24,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(
Expand All @@ -43,6 +42,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]
Expand Down

0 comments on commit dc845a8

Please sign in to comment.