Skip to content

Commit

Permalink
Explicit latest responses (#165)
Browse files Browse the repository at this point in the history
* Getting a detailed import status request (yet to do failureReasonParams and backups)

* Included failureReasonParams

* Added backup resource detail

* Upped some github actions versions
  • Loading branch information
JohnSharpe authored May 22, 2024
1 parent c6c217f commit 5b88d15
Show file tree
Hide file tree
Showing 8 changed files with 337 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4.1.5
uses: actions/checkout@v4.1.6

- name: Install Go
uses: actions/setup-go@v5.0.1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v4.1.5
uses: actions/checkout@v4.1.6

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand All @@ -50,7 +50,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -64,4 +64,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
100 changes: 93 additions & 7 deletions latest_backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"net/http/httptest"
"testing"

"github.com/RedisLabs/rediscloud-go-api/redis"
"github.com/RedisLabs/rediscloud-go-api/service/latest_backups"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -54,6 +57,29 @@ func TestGetLatestBackup(t *testing.T) {
]
}`,
),
getRequest(
t,
"/tasks/50ec6172-8475-4ef6-8b3c-d61e688d8fe5",
`{
"taskId": "50ec6172-8475-4ef6-8b3c-d61e688d8fe5",
"commandType": "databaseBackupStatusRequest",
"status": "processing-completed",
"description": "Request processing completed successfully and its resources are now being provisioned / de-provisioned.",
"timestamp": "2024-04-15T09:08:07.537915Z",
"response": {
"resourceId": 51051292,
"additionalResourceId": 12,
"resource": {}
},
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/50ec6172-8475-4ef6-8b3c-d61e688d8fe5",
"type": "GET",
"rel": "self"
}
]
}`,
),
))

subject, err := clientFromTestServer(server, "key", "secret")
Expand Down Expand Up @@ -92,14 +118,35 @@ func TestGetFixedLatestBackup(t *testing.T) {
`{
"taskId": "ce2cbfea-9b15-4250-a516-f014161a8dd3",
"commandType": "databaseBackupStatusRequest",
"status": "processing-error",
"description": "Task request failed during processing. See error information for failure details.",
"status": "processing-completed",
"description": "Request processing completed successfully and its resources are now being provisioned / de-provisioned.",
"timestamp": "2024-04-15T09:52:26.101936Z",
"response": {
"error": {
"type": "DATABASE_BACKUP_DISABLED",
"status": "400 BAD_REQUEST",
"description": "Database backup is disabled"
"resource": {
"status": "success"
}
},
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/ce2cbfea-9b15-4250-a516-f014161a8dd3",
"type": "GET",
"rel": "self"
}
]
}`,
),
getRequest(
t,
"/tasks/ce2cbfea-9b15-4250-a516-f014161a8dd3",
`{
"taskId": "ce2cbfea-9b15-4250-a516-f014161a8dd3",
"commandType": "databaseBackupStatusRequest",
"status": "processing-completed",
"description": "Request processing completed successfully and its resources are now being provisioned / de-provisioned.",
"timestamp": "2024-04-15T09:52:26.101936Z",
"response": {
"resource": {
"status": "success"
}
},
"links": [
Expand All @@ -116,8 +163,22 @@ func TestGetFixedLatestBackup(t *testing.T) {
subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)

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

assert.Equal(t, &latest_backups.LatestBackupStatus{
CommandType: redis.String("databaseBackupStatusRequest"),
Description: redis.String("Request processing completed successfully and its resources are now being provisioned / de-provisioned."),
Status: redis.String("processing-completed"),
ID: redis.String("ce2cbfea-9b15-4250-a516-f014161a8dd3"),
Response: &latest_backups.Response{
Resource: &latest_backups.Resource{
Status: redis.String("success"),
},
Error: nil,
},
}, actual)

}

func TestGetAALatestBackup(t *testing.T) {
Expand Down Expand Up @@ -168,6 +229,31 @@ func TestGetAALatestBackup(t *testing.T) {
]
}`,
),
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")
Expand Down
156 changes: 152 additions & 4 deletions latest_imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import (
"context"
"net/http/httptest"
"testing"
"time"

"github.com/RedisLabs/rediscloud-go-api/redis"
"github.com/RedisLabs/rediscloud-go-api/service/latest_imports"
"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -56,6 +61,31 @@ func TestGetLatestImportTooEarly(t *testing.T) {
]
}`,
),
getRequest(
t,
"/tasks/1dfd6084-21df-40c6-829c-e9b4790e207e",
`{
"taskId": "1dfd6084-21df-40c6-829c-e9b4790e207e",
"commandType": "databaseImportStatusRequest",
"status": "processing-error",
"description": "Task request failed during processing. See error information for failure details.",
"timestamp": "2024-04-15T10:19:07.331898Z",
"response": {
"error": {
"type": "SUBSCRIPTION_NOT_ACTIVE",
"status": "403 FORBIDDEN",
"description": "Cannot preform any actions for subscription that is not in an active state"
}
},
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/1dfd6084-21df-40c6-829c-e9b4790e207e",
"type": "GET",
"rel": "self"
}
]
}`,
),
))

subject, err := clientFromTestServer(server, "key", "secret")
Expand Down Expand Up @@ -100,7 +130,34 @@ func TestGetFixedLatestImport(t *testing.T) {
"response": {
"resourceId": 51051302,
"additionalResourceId": 110777,
"resource": {}
"resource": {
"status": "importing"
}
},
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/e9232e43-3781-4263-a38e-f4d150e03475",
"type": "GET",
"rel": "self"
}
]
}`,
),
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": {
"status": "importing"
}
},
"links": [
{
Expand All @@ -116,8 +173,22 @@ func TestGetFixedLatestImport(t *testing.T) {
subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)

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

assert.Equal(t, &latest_imports.LatestImportStatus{
CommandType: redis.String("databaseImportStatusRequest"),
Description: redis.String("Request processing completed successfully and its resources are now being provisioned / de-provisioned."),
Status: redis.String("processing-completed"),
ID: redis.String("e9232e43-3781-4263-a38e-f4d150e03475"),
Response: &latest_imports.Response{
ID: redis.Int(51051302),
Resource: &latest_imports.Resource{
Status: redis.String("importing"),
},
Error: nil,
},
}, actual)
}

func TestGetLatestImport(t *testing.T) {
Expand Down Expand Up @@ -155,7 +226,58 @@ func TestGetLatestImport(t *testing.T) {
"response": {
"resourceId": 51051302,
"additionalResourceId": 110777,
"resource": {}
"resource": {
"failureReason": "file-corrupted",
"failureReasonParams": [
{
"key": "bytes_configured_bdb_limit",
"value": "1234"
},
{
"key": "bytes_of_expected_dataset",
"value": "5678"
}
],
"lastImportTime": "2024-05-21T10:36:26Z",
"status": "failed"
}
},
"links": [
{
"href": "https://api-staging.qa.redislabs.com/v1/tasks/e9232e43-3781-4263-a38e-f4d150e03475",
"type": "GET",
"rel": "self"
}
]
}`,
),
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": {
"failureReason": "file-corrupted",
"failureReasonParams": [
{
"key": "bytes_configured_bdb_limit",
"value": "1234"
},
{
"key": "bytes_of_expected_dataset",
"value": "5678"
}
],
"lastImportTime": "2024-05-21T10:36:26Z",
"status": "failed"
}
},
"links": [
{
Expand All @@ -171,6 +293,32 @@ func TestGetLatestImport(t *testing.T) {
subject, err := clientFromTestServer(server, "key", "secret")
require.NoError(t, err)

_, err = subject.LatestImport.Get(context.TODO(), 12, 34)
actual, err := subject.LatestImport.Get(context.TODO(), 12, 34)
require.NoError(t, err)

assert.Equal(t, &latest_imports.LatestImportStatus{
CommandType: redis.String("databaseImportStatusRequest"),
Description: redis.String("Request processing completed successfully and its resources are now being provisioned / de-provisioned."),
Status: redis.String("processing-completed"),
ID: redis.String("e9232e43-3781-4263-a38e-f4d150e03475"),
Response: &latest_imports.Response{
ID: redis.Int(51051302),
Resource: &latest_imports.Resource{
Status: redis.String("failed"),
LastImportTime: redis.Time(time.Date(2024, 5, 21, 10, 36, 26, 0, time.UTC)),
FailureReason: redis.String("file-corrupted"),
FailureReasonParams: []*latest_imports.FailureReasonParam{
{
Key: redis.String("bytes_configured_bdb_limit"),
Value: redis.String("1234"),
},
{
Key: redis.String("bytes_of_expected_dataset"),
Value: redis.String("5678"),
},
},
},
Error: nil,
},
}, actual)
}
Loading

0 comments on commit 5b88d15

Please sign in to comment.