From ccce4593c1c692d063de1f80a762b4981d366c94 Mon Sep 17 00:00:00 2001 From: John Sharpe Date: Fri, 17 May 2024 15:10:58 +0100 Subject: [PATCH] Fixed end-of-page for fixed databases and added endpoints for backup and import status (#163) --- fixed_database_test.go | 18 ++++++++-- latest_backups_test.go | 57 ++++++++++++++++++++++++++++++ latest_imports_test.go | 55 ++++++++++++++++++++++++++++ service/fixed/databases/service.go | 6 ++++ service/latest_backups/service.go | 10 ++++++ service/latest_imports/service.go | 10 ++++++ 6 files changed, 153 insertions(+), 3 deletions(-) diff --git a/fixed_database_test.go b/fixed_database_test.go index 055c182..1597aaf 100644 --- a/fixed_database_test.go +++ b/fixed_database_test.go @@ -181,7 +181,7 @@ func TestFixedDatabase_List(t *testing.T) { ] }`, ), - getRequestWithQueryAndStatus( + getRequestWithQuery( t, "/fixed/subscriptions/111930/databases", map[string][]string{ @@ -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" + } ] + }`, ), ), ) diff --git a/latest_backups_test.go b/latest_backups_test.go index 3b10920..9962491 100644 --- a/latest_backups_test.go +++ b/latest_backups_test.go @@ -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( diff --git a/latest_imports_test.go b/latest_imports_test.go index c73301d..52eb111 100644 --- a/latest_imports_test.go +++ b/latest_imports_test.go @@ -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( diff --git a/service/fixed/databases/service.go b/service/fixed/databases/service.go index 31df085..72a5e3b 100644 --- a/service/fixed/databases/service.go +++ b/service/fixed/databases/service.go @@ -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() diff --git a/service/latest_backups/service.go b/service/latest_backups/service.go index d6f2e2c..3c07c82 100644 --- a/service/latest_backups/service.go +++ b/service/latest_backups/service.go @@ -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) diff --git a/service/latest_imports/service.go b/service/latest_imports/service.go index 9038d42..9d85e6f 100644 --- a/service/latest_imports/service.go +++ b/service/latest_imports/service.go @@ -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)