Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,16 @@ func (c *Client) PatchMySQLDatabase(ctx context.Context, databaseID int) error {
e := formatAPIPath("databases/mysql/instances/%d/patch", databaseID)
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
}

// SuspendMySQLDatabase suspends a MySQL Managed Database, releasing idle resources and keeping only necessary data.
// All service data is lost if there are no backups available.
func (c *Client) SuspendMySQLDatabase(ctx context.Context, databaseID int) error {
e := formatAPIPath("databases/mysql/instances/%d/suspend", databaseID)
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
}

// ResumeMySQLDatabase resumes a suspended MySQL Managed Database
func (c *Client) ResumeMySQLDatabase(ctx context.Context, databaseID int) error {
e := formatAPIPath("databases/mysql/instances/%d/resume", databaseID)
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
}
13 changes: 13 additions & 0 deletions postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,16 @@ func (c *Client) CreatePostgresDatabaseBackup(ctx context.Context, databaseID in
e := formatAPIPath("databases/postgresql/instances/%d/backups", databaseID)
return doPOSTRequestNoResponseBody(ctx, c, e, opts)
}

// SuspendPostgresDatabase suspends a PostgreSQL Managed Database, releasing idle resources and keeping only necessary data.
// All service data is lost if there are no backups available.
func (c *Client) SuspendPostgresDatabase(ctx context.Context, databaseID int) error {
e := formatAPIPath("databases/postgresql/instances/%d/suspend", databaseID)
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
}

// ResumePostgresDatabase resumes a suspended PostgreSQL Managed Database
func (c *Client) ResumePostgresDatabase(ctx context.Context, databaseID int) error {
e := formatAPIPath("databases/postgresql/instances/%d/resume", databaseID)
return doPOSTRequestNoRequestResponseBody(ctx, c, e)
}
2,474 changes: 1,698 additions & 776 deletions test/integration/fixtures/TestDatabase_MySQL_Suite.yaml

Large diffs are not rendered by default.

2,498 changes: 1,713 additions & 785 deletions test/integration/fixtures/TestDatabase_Postgres_Suite.yaml

Large diffs are not rendered by default.

24 changes: 23 additions & 1 deletion test/integration/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,29 @@ func TestDatabase_MySQL_Suite(t *testing.T) {
if err := client.WaitForDatabaseStatus(
context.Background(), database.ID, linodego.DatabaseEngineTypeMySQL,
linodego.DatabaseStatusActive, 2400); err != nil {
t.Fatalf("failed to wait for database updating: %s", err)
t.Fatalf("failed to wait for database active: %s", err)
}

if err := client.SuspendMySQLDatabase(context.Background(), database.ID); err != nil {
t.Fatalf("failed to suspend database: %s", err)
}

// Wait for the DB to enter suspended status
if err := client.WaitForDatabaseStatus(
context.Background(), database.ID, linodego.DatabaseEngineTypeMySQL,
linodego.DatabaseStatusSuspended, 240); err != nil {
t.Fatalf("failed to wait for database suspended: %s", err)
}

if err := client.ResumeMySQLDatabase(context.Background(), database.ID); err != nil {
t.Fatalf("failed to resume database: %s", err)
}

// Wait for the DB to re-enter active status
if err := client.WaitForDatabaseStatus(
context.Background(), database.ID, linodego.DatabaseEngineTypeMySQL,
linodego.DatabaseStatusActive, 2400); err != nil {
t.Fatalf("failed to wait for database active: %s", err)
}
}

Expand Down
22 changes: 22 additions & 0 deletions test/integration/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ func TestDatabase_Postgres_Suite(t *testing.T) {
linodego.DatabaseStatusActive, 2400); err != nil {
t.Fatalf("failed to wait for database updating: %s", err)
}

if err := client.SuspendPostgresDatabase(context.Background(), database.ID); err != nil {
t.Fatalf("failed to suspend database: %s", err)
}

// Wait for the DB to enter suspended status
if err := client.WaitForDatabaseStatus(
context.Background(), database.ID, linodego.DatabaseEngineTypePostgres,
linodego.DatabaseStatusSuspended, 2400); err != nil {
t.Fatalf("failed to wait for database suspended: %s", err)
}

if err := client.ResumePostgresDatabase(context.Background(), database.ID); err != nil {
t.Fatalf("failed to resume database: %s", err)
}

// Wait for the DB to re-enter active status
if err := client.WaitForDatabaseStatus(
context.Background(), database.ID, linodego.DatabaseEngineTypePostgres,
linodego.DatabaseStatusActive, 2400); err != nil {
t.Fatalf("failed to wait for database active: %s", err)
}
}

type postgresDatabaseModifier func(options *linodego.PostgresCreateOptions)
Expand Down
20 changes: 20 additions & 0 deletions test/unit/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,23 @@ func TestDatabaseMySQL_Patch(t *testing.T) {
t.Fatal(err)
}
}

func TestDatabaseMySQL_Suspend(t *testing.T) {
client := createMockClient(t)

httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "databases/mysql/instances/123/suspend"), httpmock.NewStringResponder(200, "{}"))

if err := client.SuspendMySQLDatabase(context.Background(), 123); err != nil {
t.Fatal(err)
}
}

func TestDatabaseMySQL_Resume(t *testing.T) {
client := createMockClient(t)

httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "databases/mysql/instances/123/resume"), httpmock.NewStringResponder(200, "{}"))

if err := client.ResumeMySQLDatabase(context.Background(), 123); err != nil {
t.Fatal(err)
}
}
20 changes: 20 additions & 0 deletions test/unit/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,23 @@ func TestDatabasePostgreSQL_Patch(t *testing.T) {
t.Fatal(err)
}
}

func TestDatabasePostgreSQL_Suspend(t *testing.T) {
client := createMockClient(t)

httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "databases/postgresql/instances/123/suspend"), httpmock.NewStringResponder(200, "{}"))

if err := client.SuspendPostgresDatabase(context.Background(), 123); err != nil {
t.Fatal(err)
}
}

func TestDatabasePostgreSQL_Resume(t *testing.T) {
client := createMockClient(t)

httpmock.RegisterRegexpResponder("POST", mockRequestURL(t, "databases/postgresql/instances/123/resume"), httpmock.NewStringResponder(200, "{}"))

if err := client.ResumePostgresDatabase(context.Background(), 123); err != nil {
t.Fatal(err)
}
}