Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Implement GetAccountTransfer and add DC-specific pricing fields #382

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions account_transfer.go
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
}
41 changes: 41 additions & 0 deletions test/integration/account_transfer_test.go
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))
}
}
Loading