-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subscription plans list endpoint support (#170)
* feat: Adding new subscription endpoint * feat: adding api to client, fixing up api * test: subscription test for plan subscriptions
- Loading branch information
1 parent
1038b17
commit 8a5814f
Showing
4 changed files
with
211 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package rediscloud_api | ||
|
||
import ( | ||
"context" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/RedisLabs/rediscloud-go-api/redis" | ||
"github.com/RedisLabs/rediscloud-go-api/service/fixed/plans" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const responseBody = ` | ||
{ | ||
"plans": [ | ||
{ | ||
"id": 98183, | ||
"name": "Multi-AZ 5GB", | ||
"size": 5, | ||
"sizeMeasurementUnit": "GB", | ||
"provider": "AWS", | ||
"region": "us-east-1", | ||
"regionId": 1, | ||
"price": 100, | ||
"priceCurrency": "USD", | ||
"pricePeriod": "Month", | ||
"maximumDatabases": 1, | ||
"availability": "Multi-zone", | ||
"connections": "unlimited", | ||
"cidrAllowRules": 16, | ||
"supportDataPersistence": true, | ||
"supportInstantAndDailyBackups": true, | ||
"supportReplication": true, | ||
"supportClustering": false, | ||
"supportedAlerts": [ | ||
"datasets-size", | ||
"latency", | ||
"throughput-higher-than", | ||
"throughput-lower-than" | ||
], | ||
"customerSupport": "Standard", | ||
"links": [] | ||
}, | ||
{ | ||
"id": 98181, | ||
"name": "Multi-AZ 1GB", | ||
"size": 1, | ||
"sizeMeasurementUnit": "GB", | ||
"provider": "AWS", | ||
"region": "us-east-1", | ||
"regionId": 1, | ||
"price": 22, | ||
"priceCurrency": "USD", | ||
"pricePeriod": "Month", | ||
"maximumDatabases": 1, | ||
"availability": "Multi-zone", | ||
"connections": "1024", | ||
"cidrAllowRules": 8, | ||
"supportDataPersistence": true, | ||
"supportInstantAndDailyBackups": true, | ||
"supportReplication": true, | ||
"supportClustering": false, | ||
"supportedAlerts": [ | ||
"datasets-size", | ||
"throughput-higher-than", | ||
"throughput-lower-than", | ||
"latency", | ||
"connections-limit" | ||
], | ||
"customerSupport": "Standard", | ||
"links": [] | ||
} | ||
], | ||
"links": [ | ||
{ | ||
"rel": "self", | ||
"href": "http://localhost:8081/v1/fixed/plans?cloud_provider=AWS", | ||
"type": "GET" | ||
} | ||
] | ||
}` | ||
|
||
func Test_Plans_Subscriptions_List(t *testing.T) { | ||
s := httptest.NewServer( | ||
testServer("apiKey", "secret", | ||
getRequest( | ||
t, | ||
"/fixed/plans/subscriptions/98183", | ||
responseBody, | ||
), | ||
), | ||
) | ||
|
||
subject, err := clientFromTestServer(s, "apiKey", "secret") | ||
require.NoError(t, err) | ||
|
||
actualResponse, err := subject.FixedPlanSubscriptions.List(context.TODO(), 98183) | ||
|
||
require.NoError(t, err) | ||
|
||
expectedResponse := []*plans.GetPlanResponse{ | ||
{ | ||
ID: redis.Int(98183), | ||
Name: redis.String("Multi-AZ 5GB"), | ||
Size: redis.Float64(5), | ||
SizeMeasurementUnit: redis.String("GB"), | ||
Provider: redis.String("AWS"), | ||
Region: redis.String("us-east-1"), | ||
RegionID: redis.Int(1), | ||
Price: redis.Int(100), | ||
PriceCurrency: redis.String("USD"), | ||
PricePeriod: redis.String("Month"), | ||
MaximumDatabases: redis.Int(1), | ||
Availability: redis.String("Multi-zone"), | ||
Connections: redis.String("unlimited"), | ||
CidrAllowRules: redis.Int(16), | ||
SupportDataPersistence: redis.Bool(true), | ||
SupportInstantAndDailyBackups: redis.Bool(true), | ||
SupportReplication: redis.Bool(true), | ||
SupportClustering: redis.Bool(false), | ||
SupportedAlerts: redis.StringSlice( | ||
"datasets-size", | ||
"latency", | ||
"throughput-higher-than", | ||
"throughput-lower-than"), | ||
CustomerSupport: redis.String("Standard"), | ||
}, | ||
{ | ||
ID: redis.Int(98181), | ||
Name: redis.String("Multi-AZ 1GB"), | ||
Size: redis.Float64(1), | ||
SizeMeasurementUnit: redis.String("GB"), | ||
Provider: redis.String("AWS"), | ||
Region: redis.String("us-east-1"), | ||
RegionID: redis.Int(1), | ||
Price: redis.Int(22), | ||
PriceCurrency: redis.String("USD"), | ||
PricePeriod: redis.String("Month"), | ||
MaximumDatabases: redis.Int(1), | ||
Availability: redis.String("Multi-zone"), | ||
Connections: redis.String("1024"), | ||
CidrAllowRules: redis.Int(8), | ||
SupportDataPersistence: redis.Bool(true), | ||
SupportInstantAndDailyBackups: redis.Bool(true), | ||
SupportReplication: redis.Bool(true), | ||
SupportClustering: redis.Bool(false), | ||
SupportedAlerts: redis.StringSlice( | ||
"datasets-size", | ||
"throughput-higher-than", | ||
"throughput-lower-than", | ||
"latency", | ||
"connections-limit"), | ||
CustomerSupport: redis.String("Standard"), | ||
}, | ||
} | ||
assert.Equal(t, expectedResponse, actualResponse) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package plan_subscriptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package plan_subscriptions | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/RedisLabs/rediscloud-go-api/service/fixed/plans" | ||
) | ||
|
||
const root = "/fixed/plans/subscriptions" | ||
|
||
type Log interface { | ||
Printf(format string, args ...interface{}) | ||
} | ||
|
||
type HttpClient interface { | ||
Get(ctx context.Context, name, path string, responseBody interface{}) error | ||
} | ||
|
||
type API struct { | ||
client HttpClient | ||
logger Log | ||
} | ||
|
||
func NewAPI(client HttpClient, logger Log) *API { | ||
return &API{client: client, logger: logger} | ||
} | ||
|
||
// List will list all plans upgradable from a given subscription | ||
func (a *API) List(ctx context.Context, id int) ([]*plans.GetPlanResponse, error) { | ||
var response plans.ListPlansResponse | ||
|
||
path := fmt.Sprintf("%s/%d", root, id) | ||
err := a.client.Get(ctx, "list plans for subscription plans", path, &response) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
a.logger.Printf("Listing fixed plans applicable to subscription %d, there are %d available", id, len(response.Plans)) | ||
|
||
return response.Plans, nil | ||
} |