Skip to content

Commit

Permalink
Fixed end-of-page for fixed databases and added endpoints for backup …
Browse files Browse the repository at this point in the history
…and import status
  • Loading branch information
JohnSharpe committed May 17, 2024
1 parent 0d1d7bd commit 48ec75d
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 3 deletions.
18 changes: 15 additions & 3 deletions fixed_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestFixedDatabase_List(t *testing.T) {
]
}`,
),
getRequestWithQueryAndStatus(
getRequestWithQuery(
t,
"/fixed/subscriptions/111930/databases",
map[string][]string{
Expand All @@ -192,8 +192,20 @@ func TestFixedDatabase_List(t *testing.T) {
"100",
},
},
404,
"",
`{
"accountId" : 69369,
"subscription" : {
"subscriptionId" : 111930,
"numberOfDatabases" : 0,
"databases" : [ ],
"links" : [ ]
},
"links" : [ {
"rel" : "self",
"type" : "GET",
"href" : "https://api-staging.qa.redislabs.com/v1/fixed/subscriptions/112330/databases?limit=100&offset=100"
} ]
}`,
),
),
)
Expand Down
57 changes: 57 additions & 0 deletions latest_backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,63 @@ func TestGetLatestBackup(t *testing.T) {
require.NoError(t, err)
}

func TestGetFixedLatestBackup(t *testing.T) {
server := httptest.NewServer(
testServer(
"key",
"secret",
getRequest(
t,
"/fixed/subscriptions/12/databases/34/backup",
`{
"taskId": "ce2cbfea-9b15-4250-a516-f014161a8dd3",
"commandType": "databaseBackupStatusRequest",
"status": "received",
"description": "Task request received and is being queued for processing.",
"timestamp": "2024-04-15T09:52:23.963337Z",
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/ce2cbfea-9b15-4250-a516-f014161a8dd3",
"type": "GET",
"rel": "task"
}
]
}`,
),
getRequest(
t,
"/tasks/ce2cbfea-9b15-4250-a516-f014161a8dd3",
`{
"taskId": "ce2cbfea-9b15-4250-a516-f014161a8dd3",
"commandType": "databaseBackupStatusRequest",
"status": "processing-error",
"description": "Task request failed during processing. See error information for failure details.",
"timestamp": "2024-04-15T09:52:26.101936Z",
"response": {
"error": {
"type": "DATABASE_BACKUP_DISABLED",
"status": "400 BAD_REQUEST",
"description": "Database backup is disabled"
}
},
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/ce2cbfea-9b15-4250-a516-f014161a8dd3",
"type": "GET",
"rel": "self"
}
]
}`,
),
))

subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)

_, err = subject.LatestBackup.GetFixed(context.TODO(), 12, 34)
require.NoError(t, err)
}

func TestGetAALatestBackup(t *testing.T) {
server := httptest.NewServer(
testServer(
Expand Down
55 changes: 55 additions & 0 deletions latest_imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,61 @@ func TestGetLatestImportTooEarly(t *testing.T) {
require.NoError(t, err)
}

func TestGetFixedLatestImport(t *testing.T) {
server := httptest.NewServer(
testServer(
"key",
"secret",
getRequest(
t,
"/fixed/subscriptions/12/databases/34/import",
`{
"taskId": "e9232e43-3781-4263-a38e-f4d150e03475",
"commandType": "databaseImportStatusRequest",
"status": "received",
"description": "Task request received and is being queued for processing.",
"timestamp": "2024-04-15T10:44:34.325298Z",
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/e9232e43-3781-4263-a38e-f4d150e03475",
"type": "GET",
"rel": "task"
}
]
}`,
),
getRequest(
t,
"/tasks/e9232e43-3781-4263-a38e-f4d150e03475",
`{
"taskId": "e9232e43-3781-4263-a38e-f4d150e03475",
"commandType": "databaseImportStatusRequest",
"status": "processing-completed",
"description": "Request processing completed successfully and its resources are now being provisioned / de-provisioned.",
"timestamp": "2024-04-15T10:44:35.225468Z",
"response": {
"resourceId": 51051302,
"additionalResourceId": 110777,
"resource": {}
},
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/e9232e43-3781-4263-a38e-f4d150e03475",
"type": "GET",
"rel": "self"
}
]
}`,
),
))

subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)

_, err = subject.LatestImport.GetFixed(context.TODO(), 12, 34)
require.NoError(t, err)
}

func TestGetLatestImport(t *testing.T) {
server := httptest.NewServer(
testServer(
Expand Down
6 changes: 6 additions & 0 deletions service/fixed/databases/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ func (d *ListFixedDatabase) Next() bool {
d.setError(err)
return false
}
// This API doesn't give an error when nothing is found
// If the next page is empty, we're done listing
// This is actually _better_ behaviour, but now it's inconsistent
if len(d.page) == 0 {
return false
}
}

d.updateValue()
Expand Down
10 changes: 10 additions & 0 deletions service/latest_backups/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ func (a *API) Get(ctx context.Context, subscription int, database int) (*LatestB
return NewLatestBackupStatus(task), nil
}

func (a *API) GetFixed(ctx context.Context, subscription int, database int) (*LatestBackupStatus, error) {
message := fmt.Sprintf("get latest backup information for database %d in subscription %d", subscription, database)
address := fmt.Sprintf("/fixed/subscriptions/%d/databases/%d/backup", subscription, database)
task, err := a.get(ctx, message, address)
if err != nil {
return nil, wrap404Error(subscription, database, err)
}
return NewLatestBackupStatus(task), nil
}

func (a *API) GetActiveActive(ctx context.Context, subscription int, database int, region string) (*LatestBackupStatus, error) {
message := fmt.Sprintf("get latest backup information for database %d in subscription %d and region %s", subscription, database, region)
address := fmt.Sprintf("/subscriptions/%d/databases/%d/backup?regionName=%s", subscription, database, region)
Expand Down
10 changes: 10 additions & 0 deletions service/latest_imports/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ func (a *API) Get(ctx context.Context, subscription int, database int) (*LatestI
return NewLatestImportStatus(task), nil
}

func (a *API) GetFixed(ctx context.Context, subscription int, database int) (*LatestImportStatus, error) {
message := fmt.Sprintf("get latest import information for database %d in subscription %d", subscription, database)
address := fmt.Sprintf("/fixed/subscriptions/%d/databases/%d/import", subscription, database)
task, err := a.get(ctx, message, address)
if err != nil {
return nil, wrap404Error(subscription, database, err)
}
return NewLatestImportStatus(task), nil
}

func (a *API) get(ctx context.Context, message string, address string) (*internal.Task, error) {
var taskResponse internal.TaskResponse
err := a.client.Get(ctx, message, address, &taskResponse)
Expand Down

0 comments on commit 48ec75d

Please sign in to comment.