Skip to content

Commit ef7f0f5

Browse files
committed
add missing sweep on cloud project database
1 parent f9c85eb commit ef7f0f5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

ovh/resource_cloud_project_database_database_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ovh
22

33
import (
44
"fmt"
5+
"log"
56
"os"
67
"testing"
78

@@ -30,6 +31,44 @@ resource "ovh_cloud_project_database_database" "database" {
3031
}
3132
`
3233

34+
func init() {
35+
resource.AddTestSweepers("ovh_cloud_project_database_database", &resource.Sweeper{
36+
Name: "ovh_cloud_project_database_database",
37+
F: testSweepCloudDatabaseDatabase,
38+
})
39+
}
40+
41+
func testSweepCloudDatabaseDatabase(region string) error {
42+
client, err := sharedClientForRegion(region)
43+
if err != nil {
44+
return fmt.Errorf("error getting client: %s", err)
45+
}
46+
serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST")
47+
databases := []string{"cassandra", "grafana", "kafka", "kafkaConnect", "kafkaMirrorMaker", "m3aggregator", "m3db", "mongodb", "mysql", "opensearch", "postgresql", "redis"}
48+
49+
for _, database := range databases {
50+
51+
idsToSweep := []string{}
52+
endpoint := fmt.Sprintf("/cloud/project/%s/database/%s", serviceName, database)
53+
if err := client.Get(endpoint, &idsToSweep); err != nil {
54+
return fmt.Errorf("Error calling Get %s:\n\t %q", endpoint, err)
55+
}
56+
57+
if len(idsToSweep) == 0 {
58+
log.Printf("[INFO] No %s database to sweep", database)
59+
}
60+
61+
for _, id := range idsToSweep {
62+
log.Printf("[INFO] sweeping %s database with id %s", database, id)
63+
endpoint = fmt.Sprintf("/cloud/project/%s/database/%s/%s", serviceName, database, id)
64+
if err := client.Delete(endpoint, nil); err != nil {
65+
return fmt.Errorf("Error calling Get %s:\n\t %q", endpoint, err)
66+
}
67+
}
68+
}
69+
return nil
70+
71+
}
3372
func TestAccCloudProjectDatabaseDatabase_basic(t *testing.T) {
3473
serviceName := os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST")
3574
engine := os.Getenv("OVH_CLOUD_PROJECT_DATABASE_ENGINE_TEST")

0 commit comments

Comments
 (0)