Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnSharpe committed May 14, 2024
1 parent f391a98 commit bb25d98
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 8 deletions.
164 changes: 163 additions & 1 deletion fixed_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,169 @@ func TestFixedDatabase_Create(t *testing.T) {
assert.Equal(t, 51055029, actual)
}

// TODO List
func TestFixedDatabase_List(t *testing.T) {
server := httptest.NewServer(
testServer(
"apiKey",
"secret",
getRequestWithQuery(
t,
"/fixed/subscriptions/111930/databases",
map[string][]string{
"limit": {
"100",
},
"offset": {
"0",
},
},
`{
"accountId": 69369,
"subscription": {
"subscriptionId": 111930,
"numberOfDatabases": 1,
"databases": [
{
"databaseId": 51055698,
"name": "my-second-test-fixed-database",
"protocol": "memcached",
"provider": "AWS",
"region": "us-west-1",
"respVersion": "resp2",
"status": "draft",
"planMemoryLimit": 1,
"memoryLimitMeasurementUnit": "GB",
"memoryUsedInMb": 7,
"memoryStorage": "ram",
"supportOSSClusterApi": false,
"useExternalEndpointForOSSClusterApi": false,
"dataPersistence": "none",
"replication": false,
"dataEvictionPolicy": "noeviction",
"activatedOn": "2024-05-14T09:27:48Z",
"replicaOf": null,
"replica": null,
"clustering": {
"enabled": true,
"regexRules": [
{
"ordinal": 0,
"pattern": ".*\\{(?<tag>.*)\\}.*"
},
{
"ordinal": 1,
"pattern": "(?<tag>.*)"
}
],
"hashingPolicy": "standard"
},
"security": {
"defaultUserEnabled": true,
"sslClientAuthentication": false,
"tlsClientAuthentication": false,
"enableTls": false,
"sourceIps": [
"0.0.0.0/0"
]
},
"modules": [],
"alerts": [],
"backup": {
"remoteBackupEnabled": false,
"status": "idle"
},
"links": []
}
],
"links": []
},
"links": [
{
"rel": "self",
"type": "GET",
"href": "https://api-staging.qa.redislabs.com/v1/fixed/subscriptions/111930/databases?offset=0&limit=100"
}
]
}`,
),
getRequestWithQueryAndStatus(
t,
"/fixed/subscriptions/111930/databases",
map[string][]string{
"limit": {
"100",
},
"offset": {
"100",
},
},
404,
"",
),
),
)

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

list := subject.FixedDatabases.List(context.TODO(), 111930)

var actual []*fixedDatabases.FixedDatabase
for list.Next() {
actual = append(actual, list.Value())
}
require.NoError(t, list.Err())

assert.Equal(t, []*fixedDatabases.FixedDatabase{
{
DatabaseId: redis.Int(51055698),
Name: redis.String("my-second-test-fixed-database"),
Protocol: redis.String("memcached"),
Provider: redis.String("AWS"),
Region: redis.String("us-west-1"),
RespVersion: redis.String("resp2"),
Status: redis.String("draft"),
PlanMemoryLimit: redis.Float64(1),
MemoryLimitMeasurementUnit: redis.String("GB"),
MemoryUsedInMb: redis.Float64(7),
MemoryStorage: redis.String("ram"),
SupportOSSClusterAPI: redis.Bool(false),
UseExternalEndpointForOSSClusterAPI: redis.Bool(false),
DataPersistence: redis.String("none"),
Replication: redis.Bool(false),
DataEvictionPolicy: redis.String("noeviction"),
ActivatedOn: redis.Time(time.Date(2024, 5, 14, 9, 27, 48, 0, time.UTC)),
Clustering: &fixedDatabases.Clustering{
Enabled: redis.Bool(true),
RegexRules: []*databases.RegexRule{
{
Ordinal: 0,
Pattern: ".*\\{(?<tag>.*)\\}.*",
},
{
Ordinal: 1,
Pattern: "(?<tag>.*)",
},
},
HashingPolicy: redis.String("standard"),
},
Security: &fixedDatabases.Security{
EnableDefaultUser: redis.Bool(true),
SSLClientAuthentication: redis.Bool(false),
TLSClientAuthentication: redis.Bool(false),
EnableTls: redis.Bool(false),
SourceIPs: redis.StringSlice("0.0.0.0/0"),
},
Modules: &[]*databases.Module{},
Alerts: &[]*databases.Alert{},
Backup: &fixedDatabases.Backup{
Enabled: redis.Bool(false),
Status: redis.String("idle"),
},
},
}, actual)

}

func TestFixedDatabase_Get(t *testing.T) {
server := httptest.NewServer(
Expand Down
3 changes: 3 additions & 0 deletions fixture_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rediscloud_api

import (
fixedDatabases "github.com/RedisLabs/rediscloud-go-api/service/fixed/databases"
"testing"

"github.com/RedisLabs/rediscloud-go-api/service/access_control_lists/redis_rules"
Expand Down Expand Up @@ -121,4 +122,6 @@ func TestFixedSubcriptionFixtures(t *testing.T) {
assert.Equal(t, "pending", fixedSubscriptions.FixedSubscriptionStatusPending)
assert.Equal(t, "error", fixedSubscriptions.FixedSubscriptionStatusError)
assert.Equal(t, "deleting", fixedSubscriptions.FixedSubscriptionStatusDeleting)

assert.Equal(t, []string{"redis", "memcached", "stack"}, fixedDatabases.ProtocolValues())
}
10 changes: 9 additions & 1 deletion service/fixed/databases/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (o Import) String() string {
}

type listFixedDatabaseResponse struct {
FixedSubscription []*listDbSubscription `json:"subscription,omitempty"`
FixedSubscription *listDbSubscription `json:"subscription,omitempty"`
}

func (o listFixedDatabaseResponse) String() string {
Expand All @@ -180,3 +180,11 @@ type NotFound struct {
func (f *NotFound) Error() string {
return fmt.Sprintf("fixed database %d in subscription %d not found", f.dbId, f.subId)
}

func ProtocolValues() []string {
return []string{
"redis",
"memcached",
"stack",
}
}
7 changes: 1 addition & 6 deletions service/fixed/databases/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strconv"

"github.com/RedisLabs/rediscloud-go-api/internal"
"github.com/RedisLabs/rediscloud-go-api/redis"
)

type Log interface {
Expand Down Expand Up @@ -188,11 +187,7 @@ func (d *ListFixedDatabase) nextPage() error {
return err
}

if len(list.FixedSubscription) != 1 || redis.IntValue(list.FixedSubscription[0].ID) != d.subscription {
return fmt.Errorf("server didn't respond with just a single subscription")
}

d.page = list.FixedSubscription[0].Databases
d.page = list.FixedSubscription.Databases
d.offset += d.pageSize

return nil
Expand Down

0 comments on commit bb25d98

Please sign in to comment.