|
| 1 | +package rediscloud_api |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/http/httptest" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/RedisLabs/rediscloud-go-api/redis" |
| 9 | + "github.com/RedisLabs/rediscloud-go-api/service/fixed/plans" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | +) |
| 13 | + |
| 14 | +const responseBody = ` |
| 15 | +{ |
| 16 | + "plans": [ |
| 17 | + { |
| 18 | + "id": 98183, |
| 19 | + "name": "Multi-AZ 5GB", |
| 20 | + "size": 5, |
| 21 | + "sizeMeasurementUnit": "GB", |
| 22 | + "provider": "AWS", |
| 23 | + "region": "us-east-1", |
| 24 | + "regionId": 1, |
| 25 | + "price": 100, |
| 26 | + "priceCurrency": "USD", |
| 27 | + "pricePeriod": "Month", |
| 28 | + "maximumDatabases": 1, |
| 29 | + "availability": "Multi-zone", |
| 30 | + "connections": "unlimited", |
| 31 | + "cidrAllowRules": 16, |
| 32 | + "supportDataPersistence": true, |
| 33 | + "supportInstantAndDailyBackups": true, |
| 34 | + "supportReplication": true, |
| 35 | + "supportClustering": false, |
| 36 | + "supportedAlerts": [ |
| 37 | + "datasets-size", |
| 38 | + "latency", |
| 39 | + "throughput-higher-than", |
| 40 | + "throughput-lower-than" |
| 41 | + ], |
| 42 | + "customerSupport": "Standard", |
| 43 | + "links": [] |
| 44 | + }, |
| 45 | + { |
| 46 | + "id": 98181, |
| 47 | + "name": "Multi-AZ 1GB", |
| 48 | + "size": 1, |
| 49 | + "sizeMeasurementUnit": "GB", |
| 50 | + "provider": "AWS", |
| 51 | + "region": "us-east-1", |
| 52 | + "regionId": 1, |
| 53 | + "price": 22, |
| 54 | + "priceCurrency": "USD", |
| 55 | + "pricePeriod": "Month", |
| 56 | + "maximumDatabases": 1, |
| 57 | + "availability": "Multi-zone", |
| 58 | + "connections": "1024", |
| 59 | + "cidrAllowRules": 8, |
| 60 | + "supportDataPersistence": true, |
| 61 | + "supportInstantAndDailyBackups": true, |
| 62 | + "supportReplication": true, |
| 63 | + "supportClustering": false, |
| 64 | + "supportedAlerts": [ |
| 65 | + "datasets-size", |
| 66 | + "throughput-higher-than", |
| 67 | + "throughput-lower-than", |
| 68 | + "latency", |
| 69 | + "connections-limit" |
| 70 | + ], |
| 71 | + "customerSupport": "Standard", |
| 72 | + "links": [] |
| 73 | + } |
| 74 | + ], |
| 75 | + "links": [ |
| 76 | + { |
| 77 | + "rel": "self", |
| 78 | + "href": "http://localhost:8081/v1/fixed/plans?cloud_provider=AWS", |
| 79 | + "type": "GET" |
| 80 | + } |
| 81 | + ] |
| 82 | +}` |
| 83 | + |
| 84 | +func Test_Plans_Subscriptions_List(t *testing.T) { |
| 85 | + s := httptest.NewServer( |
| 86 | + testServer("apiKey", "secret", |
| 87 | + getRequest( |
| 88 | + t, |
| 89 | + "/fixed/plans/subscriptions/98183", |
| 90 | + responseBody, |
| 91 | + ), |
| 92 | + ), |
| 93 | + ) |
| 94 | + |
| 95 | + subject, err := clientFromTestServer(s, "apiKey", "secret") |
| 96 | + require.NoError(t, err) |
| 97 | + |
| 98 | + actualResponse, err := subject.FixedPlanSubscriptions.List(context.TODO(), 98183) |
| 99 | + |
| 100 | + require.NoError(t, err) |
| 101 | + |
| 102 | + expectedResponse := []*plans.GetPlanResponse{ |
| 103 | + { |
| 104 | + ID: redis.Int(98183), |
| 105 | + Name: redis.String("Multi-AZ 5GB"), |
| 106 | + Size: redis.Float64(5), |
| 107 | + SizeMeasurementUnit: redis.String("GB"), |
| 108 | + Provider: redis.String("AWS"), |
| 109 | + Region: redis.String("us-east-1"), |
| 110 | + RegionID: redis.Int(1), |
| 111 | + Price: redis.Int(100), |
| 112 | + PriceCurrency: redis.String("USD"), |
| 113 | + PricePeriod: redis.String("Month"), |
| 114 | + MaximumDatabases: redis.Int(1), |
| 115 | + Availability: redis.String("Multi-zone"), |
| 116 | + Connections: redis.String("unlimited"), |
| 117 | + CidrAllowRules: redis.Int(16), |
| 118 | + SupportDataPersistence: redis.Bool(true), |
| 119 | + SupportInstantAndDailyBackups: redis.Bool(true), |
| 120 | + SupportReplication: redis.Bool(true), |
| 121 | + SupportClustering: redis.Bool(false), |
| 122 | + SupportedAlerts: redis.StringSlice( |
| 123 | + "datasets-size", |
| 124 | + "latency", |
| 125 | + "throughput-higher-than", |
| 126 | + "throughput-lower-than"), |
| 127 | + CustomerSupport: redis.String("Standard"), |
| 128 | + }, |
| 129 | + { |
| 130 | + ID: redis.Int(98181), |
| 131 | + Name: redis.String("Multi-AZ 1GB"), |
| 132 | + Size: redis.Float64(1), |
| 133 | + SizeMeasurementUnit: redis.String("GB"), |
| 134 | + Provider: redis.String("AWS"), |
| 135 | + Region: redis.String("us-east-1"), |
| 136 | + RegionID: redis.Int(1), |
| 137 | + Price: redis.Int(22), |
| 138 | + PriceCurrency: redis.String("USD"), |
| 139 | + PricePeriod: redis.String("Month"), |
| 140 | + MaximumDatabases: redis.Int(1), |
| 141 | + Availability: redis.String("Multi-zone"), |
| 142 | + Connections: redis.String("1024"), |
| 143 | + CidrAllowRules: redis.Int(8), |
| 144 | + SupportDataPersistence: redis.Bool(true), |
| 145 | + SupportInstantAndDailyBackups: redis.Bool(true), |
| 146 | + SupportReplication: redis.Bool(true), |
| 147 | + SupportClustering: redis.Bool(false), |
| 148 | + SupportedAlerts: redis.StringSlice( |
| 149 | + "datasets-size", |
| 150 | + "throughput-higher-than", |
| 151 | + "throughput-lower-than", |
| 152 | + "latency", |
| 153 | + "connections-limit"), |
| 154 | + CustomerSupport: redis.String("Standard"), |
| 155 | + }, |
| 156 | + } |
| 157 | + assert.Equal(t, expectedResponse, actualResponse) |
| 158 | +} |
0 commit comments