-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(sweeper): add missing sweepers (#456)
- Loading branch information
Showing
12 changed files
with
395 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,42 @@ import ( | |
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
account "github.com/scaleway/scaleway-sdk-go/api/account/v2alpha1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
func init() { | ||
resource.AddTestSweepers("scaleway_account_ssh_key", &resource.Sweeper{ | ||
Name: "scaleway_account_ssh_key", | ||
F: testSweepAccountSSHKey, | ||
}) | ||
} | ||
|
||
func testSweepAccountSSHKey(region string) error { | ||
scwClient, err := sharedClientForRegion(region) | ||
if err != nil { | ||
return fmt.Errorf("error getting client in sweeper: %s", err) | ||
} | ||
accountAPI := account.NewAPI(scwClient) | ||
|
||
l.Debugf("sweeper: destroying the SSH keys") | ||
|
||
listSSHKeys, err := accountAPI.ListSSHKeys(&account.ListSSHKeysRequest{}, scw.WithAllPages()) | ||
if err != nil { | ||
return fmt.Errorf("error listing SSH keys in sweeper: %s", err) | ||
} | ||
|
||
for _, sshKey := range listSSHKeys.SSHKeys { | ||
err := accountAPI.DeleteSSHKey(&account.DeleteSSHKeyRequest{ | ||
SSHKeyID: sshKey.ID, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("error deleting SSH key in sweeper: %s", err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func TestAccScalewayAccountSSHKey(t *testing.T) { | ||
name := newRandomName("ssh-key") | ||
SSHKey := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEEYrzDOZmhItdKaDAEqJQ4ORS2GyBMtBozYsK5kiXXX [email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,40 @@ import ( | |
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1alpha1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
func init() { | ||
resource.AddTestSweepers("scaleway_baremetal_server_beta", &resource.Sweeper{ | ||
Name: "scaleway_baremetal_server_beta", | ||
F: testSweepBaremetalServer, | ||
}) | ||
} | ||
|
||
func testSweepBaremetalServer(region string) error { | ||
return sweepZones(region, func(scwClient *scw.Client) error { | ||
baremetalAPI := baremetal.NewAPI(scwClient) | ||
zone, _ := scwClient.GetDefaultZone() | ||
l.Debugf("sweeper: destroying the baremetal server in (%s)", zone) | ||
listServers, err := baremetalAPI.ListServers(&baremetal.ListServersRequest{}, scw.WithAllPages()) | ||
if err != nil { | ||
l.Warningf("error listing servers in (%s) in sweeper: %s", zone, err) | ||
return nil | ||
} | ||
|
||
for _, server := range listServers.Servers { | ||
_, err := baremetalAPI.DeleteServer(&baremetal.DeleteServerRequest{ | ||
ServerID: server.ID, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("error deleting server in sweeper: %s", err) | ||
} | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
func TestAccScalewayBaremetalServerBetaMinimal1(t *testing.T) { | ||
SSHKeyName := newRandomName("ssh-key") | ||
SSHKey := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM7HUxRyQtB2rnlhQUcbDGCZcTJg7OvoznOiyC9W6IxH [email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.