Skip to content

Commit

Permalink
test: subscription test for plan subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
burythehammer committed Jul 8, 2024
1 parent fb5f00b commit 3b121c7
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 6 deletions.
3 changes: 2 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rediscloud_api
import (
"bytes"
"encoding/json"
"github.com/RedisLabs/rediscloud-go-api/service/fixed/plans/plan_subscriptions"
"log"
"net/http"
"net/http/httputil"
Expand All @@ -21,7 +20,9 @@ import (
"github.com/RedisLabs/rediscloud-go-api/service/databases"
fixedDatabases "github.com/RedisLabs/rediscloud-go-api/service/fixed/databases"
"github.com/RedisLabs/rediscloud-go-api/service/fixed/plans"
"github.com/RedisLabs/rediscloud-go-api/service/fixed/plans/plan_subscriptions"
fixedSubscriptions "github.com/RedisLabs/rediscloud-go-api/service/fixed/subscriptions"

"github.com/RedisLabs/rediscloud-go-api/service/latest_backups"
"github.com/RedisLabs/rediscloud-go-api/service/latest_imports"
"github.com/RedisLabs/rediscloud-go-api/service/pricing"
Expand Down
158 changes: 158 additions & 0 deletions fixed_plans_subscriptions_test.go
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)
}
10 changes: 5 additions & 5 deletions service/fixed/plans/plan_subscriptions/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package plan_subscriptions
import (
"context"
"fmt"

"github.com/RedisLabs/rediscloud-go-api/service/fixed/plans"
"net/url"
)

const root = "/fixed/plans/subscriptions"
Expand All @@ -15,7 +15,6 @@ type Log interface {

type HttpClient interface {
Get(ctx context.Context, name, path string, responseBody interface{}) error
GetWithQuery(ctx context.Context, name, path string, query url.Values, responseBody interface{}) error
}

type API struct {
Expand All @@ -27,16 +26,17 @@ func NewAPI(client HttpClient, logger Log) *API {
return &API{client: client, logger: logger}
}

// List will list all subscriptions with a specific plan
// 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

err := a.client.Get(ctx, "list plans for subscription plans", fmt.Sprintf("%s/%d", root, id), &response)
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, all cloud providers, there are %d available", len(response.Plans))
a.logger.Printf("Listing fixed plans applicable to subscription %d, there are %d available", id, len(response.Plans))

return response.Plans, nil
}

0 comments on commit 3b121c7

Please sign in to comment.