-
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.
- Loading branch information
1 parent
bbf2806
commit e026e53
Showing
4 changed files
with
125 additions
and
0 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,52 @@ | ||
package rediscloud_api | ||
|
||
import ( | ||
"context" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGet(t *testing.T) { | ||
server := httptest.NewServer( | ||
testServer( | ||
"key", | ||
"secret", | ||
getRequest( | ||
t, | ||
"/subscriptions/12/databases/34/pricing", | ||
`[ | ||
{ | ||
"type": "Shards", | ||
"typeDetails": "micro", | ||
"quantity": 1, | ||
"quantityMeasurement": "shards", | ||
"pricePerUnit": 0.027, | ||
"priceCurrency": "USD", | ||
"pricePeriod": "hour" | ||
}, | ||
[ | ||
{ | ||
"rel": "self", | ||
"href": "https://api-staging.qa.redislabs.com/v1/subscriptions/110777/pricing", | ||
"type": "GET" | ||
} | ||
] | ||
]`, | ||
), | ||
)) | ||
|
||
subject, err := clientFromTestServer(server, "key", "secret") | ||
require.NoError(t, err) | ||
|
||
_, err = subject.Pricing.List(context.TODO(), 20000) | ||
require.NoError(t, err) | ||
|
||
//assert.Equal(t, &users.GetUserResponse{ | ||
// ID: redis.Int(20000), | ||
// Name: redis.String("test-user"), | ||
// Role: redis.String("test-role"), | ||
// Status: redis.String(users.StatusPending), | ||
//}, actual) | ||
} |
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,31 @@ | ||
package pricing | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/RedisLabs/rediscloud-go-api/internal" | ||
) | ||
|
||
type Pricing struct { | ||
DatabaseName *string `json:"databaseName,omitempty"` | ||
Type *string `json:"type,omitempty"` | ||
TypeDetails *string `json:"typeDetails,omitempty"` | ||
Quantity *int `json:"quantity,omitempty"` | ||
QuantityMeasurement *string `json:"quantityMeasurement,omitempty"` | ||
PricePerUnit *float64 `json:"pricePerUnit,omitempty"` | ||
PriceCurrency *string `json:"priceCurrency,omitempty"` | ||
PricePeriod *string `json:"pricePeriod,omitempty"` | ||
Region *string `json:"region,omitempty"` | ||
} | ||
|
||
func (o Pricing) String() string { | ||
return internal.ToString(o) | ||
} | ||
|
||
type NotFound struct { | ||
subId int | ||
} | ||
|
||
func (f *NotFound) Error() string { | ||
return fmt.Sprintf("subscription %d not found", f.subId) | ||
} |
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,32 @@ | ||
package pricing | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
type HttpClient interface { | ||
Get(ctx context.Context, name, path string, responseBody interface{}) error | ||
} | ||
|
||
type API struct { | ||
client HttpClient | ||
} | ||
|
||
func NewAPI(client HttpClient) *API { | ||
return &API{client: client} | ||
} | ||
|
||
// List will return the list of available pricing detail blocks for the provided subscription. | ||
func (a *API) List(ctx context.Context, subscription int) ([]*Pricing, error) { | ||
var body []*Pricing | ||
|
||
message := fmt.Sprintf("get pricing information for subscription %d", subscription) | ||
address := fmt.Sprintf("/subscriptions/%d/pricing", subscription) | ||
|
||
if err := a.client.Get(ctx, message, address, &body); err != nil { | ||
return nil, err | ||
} | ||
|
||
return body, nil | ||
} |