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

account: Now may include info on current team. #536

Merged
merged 1 commit into from
Jun 2, 2022
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
23 changes: 15 additions & 8 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ var _ AccountService = &AccountServiceOp{}

// Account represents a DigitalOcean Account
type Account struct {
DropletLimit int `json:"droplet_limit,omitempty"`
FloatingIPLimit int `json:"floating_ip_limit,omitempty"`
VolumeLimit int `json:"volume_limit,omitempty"`
Email string `json:"email,omitempty"`
UUID string `json:"uuid,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
Status string `json:"status,omitempty"`
StatusMessage string `json:"status_message,omitempty"`
DropletLimit int `json:"droplet_limit,omitempty"`
FloatingIPLimit int `json:"floating_ip_limit,omitempty"`
VolumeLimit int `json:"volume_limit,omitempty"`
Email string `json:"email,omitempty"`
UUID string `json:"uuid,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
Status string `json:"status,omitempty"`
StatusMessage string `json:"status_message,omitempty"`
Team *TeamInfo `json:"team,omitempty"`
}

// TeamInfo contains information about the currently team context.
type TeamInfo struct {
Name string `json:"name,omitempty"`
UUID string `json:"uuid,omitempty"`
}

type accountRoot struct {
Expand Down
71 changes: 71 additions & 0 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,74 @@ func TestAccountString(t *testing.T) {
}

}

func TestAccountGetWithTeam(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/v2/account", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)

response := `
{ "account": {
"droplet_limit": 25,
"floating_ip_limit": 25,
"volume_limit": 22,
"email": "sammy@digitalocean.com",
"uuid": "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
"email_verified": true,
"team": {
"name": "My Team",
"uuid": "b6fr89dbf6d9156cace5f3c78dc9851d957381ef"
}
}
}`

fmt.Fprint(w, response)
})

acct, _, err := client.Account.Get(ctx)
if err != nil {
t.Errorf("Account.Get returned error: %v", err)
}

expected := &Account{
DropletLimit: 25,
FloatingIPLimit: 25,
Email: "sammy@digitalocean.com",
UUID: "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
EmailVerified: true,
VolumeLimit: 22,
Team: &TeamInfo{
Name: "My Team",
UUID: "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
},
}
if !reflect.DeepEqual(acct, expected) {
t.Errorf("Account.Get returned %+v, expected %+v", acct, expected)
}
}

func TestAccountStringWithTeam(t *testing.T) {
acct := &Account{
DropletLimit: 25,
FloatingIPLimit: 25,
Email: "sammy@digitalocean.com",
UUID: "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
EmailVerified: true,
Status: "active",
StatusMessage: "message",
VolumeLimit: 22,
Team: &TeamInfo{
Name: "My Team",
UUID: "b6fr89dbf6d9156cace5f3c78dc9851d957381ef",
},
}

stringified := acct.String()
expected := `godo.Account{DropletLimit:25, FloatingIPLimit:25, VolumeLimit:22, Email:"sammy@digitalocean.com", UUID:"b6fr89dbf6d9156cace5f3c78dc9851d957381ef", EmailVerified:true, Status:"active", StatusMessage:"message", Team:godo.TeamInfo{Name:"My Team", UUID:"b6fr89dbf6d9156cace5f3c78dc9851d957381ef"}}`
if expected != stringified {
t.Errorf("Account.String returned %+v, expected %+v", stringified, expected)
}

}