-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from linode/proj/dc-specific-pricing
project: DC-Specific Pricing Support
- Loading branch information
Showing
6 changed files
with
415 additions
and
13 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,33 @@ | ||
package linodego | ||
|
||
import "context" | ||
|
||
// AccountTransfer represents an Account's network utilization for the current month. | ||
type AccountTransfer struct { | ||
Billable int `json:"billable"` | ||
Quota int `json:"quota"` | ||
Used int `json:"used"` | ||
|
||
RegionTransfers []AccountTransferRegion `json:"region_transfers"` | ||
} | ||
|
||
// AccountTransferRegion represents an Account's network utilization for the current month | ||
// in a given region. | ||
type AccountTransferRegion struct { | ||
ID string `json:"id"` | ||
Billable int `json:"billable"` | ||
Quota int `json:"quota"` | ||
Used int `json:"used"` | ||
} | ||
|
||
// GetAccountTransfer gets current Account's network utilization for the current month. | ||
func (c *Client) GetAccountTransfer(ctx context.Context) (*AccountTransfer, error) { | ||
req := c.R(ctx).SetResult(&AccountTransfer{}) | ||
e := "account/transfer" | ||
r, err := coupleAPIErrors(req.Get(e)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return r.Result().(*AccountTransfer), nil | ||
} |
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,41 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/jarcoal/httpmock" | ||
"github.com/linode/linodego" | ||
) | ||
|
||
func TestAccount_getTransfer(t *testing.T) { | ||
client := createMockClient(t) | ||
|
||
desiredResponse := linodego.AccountTransfer{ | ||
Billable: 123, | ||
Quota: 456, | ||
Used: 789, | ||
RegionTransfers: []linodego.AccountTransferRegion{ | ||
{ | ||
ID: "us-southeast", | ||
Billable: 987, | ||
Quota: 654, | ||
Used: 3211, | ||
}, | ||
}, | ||
} | ||
|
||
httpmock.RegisterRegexpResponder("GET", mockRequestURL(t, "/account/transfer"), | ||
httpmock.NewJsonResponderOrPanic(200, &desiredResponse)) | ||
|
||
questions, err := client.GetAccountTransfer(context.Background()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !reflect.DeepEqual(*questions, desiredResponse) { | ||
t.Fatalf("actual response does not equal desired response: %s", cmp.Diff(questions, desiredResponse)) | ||
} | ||
} |
Oops, something went wrong.