ditch pagination, unused on greenhost
This commit is contained in:
parent
e3da364db1
commit
9c1271cbfa
|
@ -0,0 +1,6 @@
|
|||
|
||||
ID: ?(\d+)
|
||||
ID: "$1"
|
||||
|
||||
"id": ?(\d+)
|
||||
"id": "$1"
|
|
@ -33,7 +33,7 @@ var _ ActionsService = &ActionsServiceOp{}
|
|||
|
||||
type actionsRoot struct {
|
||||
Actions []Action `json:"actions"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
|
@ -51,16 +51,14 @@ func TestAction_ListActionMultiplePages(t *testing.T) {
|
|||
defer teardown()
|
||||
|
||||
mux.HandleFunc("/v2/actions", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, `{"actions": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/droplets/?page=2"}}}`)
|
||||
fmt.Fprint(w, `{"actions": [{"id":1},{"id":2}], "links":[]}`)
|
||||
testMethod(t, r, http.MethodGet)
|
||||
})
|
||||
|
||||
_, resp, err := client.Actions.List(ctx, nil)
|
||||
_, _, err := client.Actions.List(ctx, nil)
|
||||
if err != nil {
|
||||
t.Fatal(nil)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestAction_RetrievePageByNumber(t *testing.T) {
|
||||
|
@ -70,14 +68,7 @@ func TestAction_RetrievePageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"actions": [{"id":1},{"id":2}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/actions/?page=3",
|
||||
"prev":"http://example.com/v2/actions/?page=1",
|
||||
"last":"http://example.com/v2/actions/?page=3",
|
||||
"first":"http://example.com/v2/actions/?page=1"
|
||||
}
|
||||
}
|
||||
"links":[]
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/actions", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -86,12 +77,10 @@ func TestAction_RetrievePageByNumber(t *testing.T) {
|
|||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.Actions.List(ctx, opt)
|
||||
_, _, err := client.Actions.List(ctx, opt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestAction_Get(t *testing.T) {
|
||||
|
|
4
apps.go
4
apps.go
|
@ -80,7 +80,7 @@ type appRoot struct {
|
|||
|
||||
type appsRoot struct {
|
||||
Apps []*App `json:"apps"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ type deploymentRoot struct {
|
|||
|
||||
type deploymentsRoot struct {
|
||||
Deployments []*Deployment `json:"deployments"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
10
apps_test.go
10
apps_test.go
|
@ -259,16 +259,13 @@ func TestApps_ListApp(t *testing.T) {
|
|||
mux.HandleFunc("/v2/apps", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
|
||||
json.NewEncoder(w).Encode(&appsRoot{Apps: []*App{&testApp}, Meta: &Meta{Total: 1}, Links: &Links{}})
|
||||
json.NewEncoder(w).Encode(&appsRoot{Apps: []*App{&testApp}, Meta: &Meta{Total: 1}, Links: []*LinkAction{}})
|
||||
})
|
||||
|
||||
apps, resp, err := client.Apps.List(ctx, nil)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*App{&testApp}, apps)
|
||||
assert.Equal(t, 1, resp.Meta.Total)
|
||||
currentPage, err := resp.Links.CurrentPage()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, currentPage)
|
||||
}
|
||||
|
||||
func TestApps_UpdateApp(t *testing.T) {
|
||||
|
@ -421,16 +418,13 @@ func TestApps_ListDeployments(t *testing.T) {
|
|||
mux.HandleFunc(fmt.Sprintf("/v2/apps/%s/deployments", testApp.ID), func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
|
||||
json.NewEncoder(w).Encode(&deploymentsRoot{Deployments: []*Deployment{&testDeployment}, Meta: &Meta{Total: 1}, Links: &Links{}})
|
||||
json.NewEncoder(w).Encode(&deploymentsRoot{Deployments: []*Deployment{&testDeployment}, Meta: &Meta{Total: 1}, Links: []*LinkAction{}})
|
||||
})
|
||||
|
||||
deployments, resp, err := client.Apps.ListDeployments(ctx, testApp.ID, nil)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []*Deployment{&testDeployment}, deployments)
|
||||
assert.Equal(t, 1, resp.Meta.Total)
|
||||
currentPage, err := resp.Links.CurrentPage()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 1, currentPage)
|
||||
}
|
||||
|
||||
func TestApps_GetLogs(t *testing.T) {
|
||||
|
|
|
@ -26,7 +26,7 @@ var _ BillingHistoryService = &BillingHistoryServiceOp{}
|
|||
// BillingHistory represents a DigitalOcean Billing History
|
||||
type BillingHistory struct {
|
||||
BillingHistory []BillingHistoryEntry `json:"billing_history"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
2
cdn.go
2
cdn.go
|
@ -46,7 +46,7 @@ type cdnRoot struct {
|
|||
|
||||
type cdnsRoot struct {
|
||||
Endpoints []CDN `json:"endpoints"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
16
cdn_test.go
16
cdn_test.go
|
@ -99,17 +99,15 @@ func TestCDN_ListCDNMultiplePages(t *testing.T) {
|
|||
"created_at": "2012-10-03T15:00:01.05Z"
|
||||
}
|
||||
],
|
||||
"links":{"pages":{"next":"http://example.com/v2/cdn/endpoints/?page=2"}}
|
||||
"links":[]
|
||||
}`,
|
||||
)
|
||||
})
|
||||
|
||||
_, resp, err := client.CDNs.List(ctx, nil)
|
||||
_, _, err := client.CDNs.List(ctx, nil)
|
||||
if err != nil {
|
||||
t.Errorf("CDNs.List multiple page returned error: %v", err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestCDN_RetrievePageByNumber(t *testing.T) {
|
||||
|
@ -137,21 +135,15 @@ func TestCDN_RetrievePageByNumber(t *testing.T) {
|
|||
"created_at": "2012-10-03T15:00:01.05Z"
|
||||
}
|
||||
],
|
||||
"links":{"pages":{
|
||||
"next":"http://example.com/v2/cdn/endpoints/?page=3",
|
||||
"prev":"http://example.com/v2/cdn/endpoints/?page=1",
|
||||
"last":"http://example.com/v2/cdn/endpoints/?page=3",
|
||||
"first":"http://example.com/v2/cdn/endpoints/?page=1"}}
|
||||
"links":[]
|
||||
}`,
|
||||
)
|
||||
})
|
||||
|
||||
_, resp, err := client.CDNs.List(ctx, &ListOptions{Page: 2})
|
||||
_, _, err := client.CDNs.List(ctx, &ListOptions{Page: 2})
|
||||
if err != nil {
|
||||
t.Errorf("CDNs.List singular page returned error: %v", err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestCDN_GetCDN(t *testing.T) {
|
||||
|
|
|
@ -45,7 +45,7 @@ type certificateRoot struct {
|
|||
|
||||
type certificatesRoot struct {
|
||||
Certificates []Certificate `json:"certificates"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ var certsJSONResponse = `
|
|||
"type": "lets_encrypt"
|
||||
}
|
||||
],
|
||||
"links": {},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 2
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ type domainRoot struct {
|
|||
|
||||
type domainsRoot struct {
|
||||
Domains []Domain `json:"domains"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ type domainRecordRoot struct {
|
|||
// DomainRecordsRoot is the root of a group of Domain Record responses
|
||||
type domainRecordsRoot struct {
|
||||
DomainRecords []DomainRecord `json:"domain_records"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
}
|
||||
|
||||
// DomainRecord represents a DigitalOcean DomainRecord
|
||||
|
|
|
@ -48,15 +48,13 @@ func TestDomains_ListDomainsMultiplePages(t *testing.T) {
|
|||
|
||||
mux.HandleFunc("/v2/domains", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
fmt.Fprint(w, `{"domains": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/domains/?page=2"}}}`)
|
||||
fmt.Fprint(w, `{"domains": [{"id":1},{"id":2}], "links":[]}`)
|
||||
})
|
||||
|
||||
_, resp, err := client.Domains.List(ctx, nil)
|
||||
_, _, err := client.Domains.List(ctx, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestDomains_RetrievePageByNumber(t *testing.T) {
|
||||
|
@ -66,14 +64,7 @@ func TestDomains_RetrievePageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"domains": [{"id":1},{"id":2}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/domains/?page=3",
|
||||
"prev":"http://example.com/v2/domains/?page=1",
|
||||
"last":"http://example.com/v2/domains/?page=3",
|
||||
"first":"http://example.com/v2/domains/?page=1"
|
||||
}
|
||||
},
|
||||
"links":[],
|
||||
"meta":{
|
||||
"total":2
|
||||
}
|
||||
|
@ -85,12 +76,10 @@ func TestDomains_RetrievePageByNumber(t *testing.T) {
|
|||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.Domains.List(ctx, opt)
|
||||
_, _, err := client.Domains.List(ctx, opt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestDomains_GetDomain(t *testing.T) {
|
||||
|
|
10
droplets.go
10
droplets.go
|
@ -135,30 +135,30 @@ func (d Droplet) URN() string {
|
|||
// DropletRoot represents a Droplet root
|
||||
type dropletRoot struct {
|
||||
Droplet *Droplet `json:"droplet"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
type dropletsRoot struct {
|
||||
Droplets []Droplet `json:"droplets"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type kernelsRoot struct {
|
||||
Kernels []Kernel `json:"kernels,omitempty"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type dropletSnapshotsRoot struct {
|
||||
Snapshots []Image `json:"snapshots,omitempty"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type backupsRoot struct {
|
||||
Backups []Image `json:"backups,omitempty"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
|
@ -135,9 +135,7 @@ func TestDroplets_ListDropletsMultiplePages(t *testing.T) {
|
|||
{ID: 1},
|
||||
{ID: 2},
|
||||
},
|
||||
Links: &Links{
|
||||
Pages: &Pages{Next: "http://example.com/v2/droplets/?page=2"},
|
||||
},
|
||||
Links: nil,
|
||||
}
|
||||
|
||||
b, err := json.Marshal(dr)
|
||||
|
@ -148,12 +146,10 @@ func TestDroplets_ListDropletsMultiplePages(t *testing.T) {
|
|||
fmt.Fprint(w, string(b))
|
||||
})
|
||||
|
||||
_, resp, err := client.Droplets.List(ctx, nil)
|
||||
_, _, err := client.Droplets.List(ctx, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestDroplets_RetrievePageByNumber(t *testing.T) {
|
||||
|
@ -163,14 +159,7 @@ func TestDroplets_RetrievePageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"droplets": [{"id":1},{"id":2}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/droplets/?page=3",
|
||||
"prev":"http://example.com/v2/droplets/?page=1",
|
||||
"last":"http://example.com/v2/droplets/?page=3",
|
||||
"first":"http://example.com/v2/droplets/?page=1"
|
||||
}
|
||||
}
|
||||
"links": []
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/droplets", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -179,12 +168,10 @@ func TestDroplets_RetrievePageByNumber(t *testing.T) {
|
|||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.Droplets.List(ctx, opt)
|
||||
_, _, err := client.Droplets.List(ctx, opt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestDroplets_GetDroplet(t *testing.T) {
|
||||
|
@ -250,15 +237,13 @@ func TestDroplets_Create(t *testing.T) {
|
|||
"id": 1,
|
||||
"vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6"
|
||||
},
|
||||
"links": {
|
||||
"actions": [
|
||||
{
|
||||
"id": 1,
|
||||
"href": "http://example.com",
|
||||
"rel": "create"
|
||||
}
|
||||
]
|
||||
}
|
||||
"links": [
|
||||
{
|
||||
"id": 1,
|
||||
"href": "http://example.com",
|
||||
"rel": "create"
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
|
@ -289,7 +274,7 @@ func TestDroplets_Create(t *testing.T) {
|
|||
t.Errorf("expected VPC uuid '%s', received '%s'", vpcid, id)
|
||||
}
|
||||
|
||||
if a := resp.Links.Actions[0]; a.ID != 1 {
|
||||
if a := resp.Links[0]; a.ID != 1 {
|
||||
t.Errorf("expected action id '%d', received '%d'", 1, a.ID)
|
||||
}
|
||||
}
|
||||
|
@ -340,15 +325,13 @@ func TestDroplets_CreateWithoutDropletAgent(t *testing.T) {
|
|||
"id": 1,
|
||||
"vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6"
|
||||
},
|
||||
"links": {
|
||||
"actions": [
|
||||
{
|
||||
"id": 1,
|
||||
"href": "http://example.com",
|
||||
"rel": "create"
|
||||
}
|
||||
]
|
||||
}
|
||||
"links": [
|
||||
{
|
||||
"id": 1,
|
||||
"href": "http://example.com",
|
||||
"rel": "create"
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
|
@ -379,7 +362,7 @@ func TestDroplets_CreateWithoutDropletAgent(t *testing.T) {
|
|||
t.Errorf("expected VPC uuid '%s', received '%s'", vpcid, id)
|
||||
}
|
||||
|
||||
if a := resp.Links.Actions[0]; a.ID != 1 {
|
||||
if a := resp.Links[0]; a.ID != 1 {
|
||||
t.Errorf("expected action id '%d', received '%d'", 1, a.ID)
|
||||
}
|
||||
}
|
||||
|
@ -459,15 +442,13 @@ func TestDroplets_CreateWithDisabledPublicNetworking(t *testing.T) {
|
|||
"id": 1,
|
||||
"vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6"
|
||||
},
|
||||
"links": {
|
||||
"actions": [
|
||||
{
|
||||
"id": 1,
|
||||
"href": "http://example.com",
|
||||
"rel": "create"
|
||||
}
|
||||
]
|
||||
}
|
||||
"links": [
|
||||
{
|
||||
"id": 1,
|
||||
"href": "http://example.com",
|
||||
"rel": "create"
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
|
@ -535,15 +516,13 @@ func TestDroplets_CreateMultiple(t *testing.T) {
|
|||
"vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6"
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"actions": [
|
||||
{
|
||||
"id": 1,
|
||||
"href": "http://example.com",
|
||||
"rel": "multiple_create"
|
||||
}
|
||||
]
|
||||
}
|
||||
"links": [
|
||||
{
|
||||
"id": 1,
|
||||
"href": "http://example.com",
|
||||
"rel": "multiple_create"
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
|
@ -580,7 +559,7 @@ func TestDroplets_CreateMultiple(t *testing.T) {
|
|||
t.Errorf("expected VPC uuid '%s', received '%s'", vpcid, id)
|
||||
}
|
||||
|
||||
if a := resp.Links.Actions[0]; a.ID != 1 {
|
||||
if a := resp.Links[0]; a.ID != 1 {
|
||||
t.Errorf("expected action id '%d', received '%d'", 1, a.ID)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ type firewallRoot struct {
|
|||
|
||||
type firewallsRoot struct {
|
||||
Firewalls []Firewall `json:"firewalls"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ var (
|
|||
]
|
||||
}
|
||||
],
|
||||
"links": {},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 1
|
||||
}
|
||||
|
|
|
@ -44,13 +44,13 @@ func (f FloatingIP) URN() string {
|
|||
|
||||
type floatingIPsRoot struct {
|
||||
FloatingIPs []FloatingIP `json:"floating_ips"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type floatingIPRoot struct {
|
||||
FloatingIP *FloatingIP `json:"floating_ip"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
// FloatingIPCreateRequest represents a request to create a floating IP.
|
||||
|
|
|
@ -124,15 +124,13 @@ func TestFloatingIPsActions_ListMultiplePages(t *testing.T) {
|
|||
|
||||
mux.HandleFunc("/v2/floating_ips/192.168.0.1/actions", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
fmt.Fprint(w, `{"actions":[{"status":"in-progress"}], "links":{"pages":{"next":"http://example.com/v2/floating_ips/192.168.0.1/actions?page=2"}}}`)
|
||||
fmt.Fprint(w, `{"actions":[{"status":"in-progress"}], "links":[]}`)
|
||||
})
|
||||
|
||||
_, resp, err := client.FloatingIPActions.List(ctx, "192.168.0.1", nil)
|
||||
_, _, err := client.FloatingIPActions.List(ctx, "192.168.0.1", nil)
|
||||
if err != nil {
|
||||
t.Errorf("FloatingIPsActions.List returned error: %v", err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestFloatingIPsActions_ListPageByNumber(t *testing.T) {
|
||||
|
@ -142,14 +140,7 @@ func TestFloatingIPsActions_ListPageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"actions":[{"status":"in-progress"}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/floating_ips/?page=3",
|
||||
"prev":"http://example.com/v2/floating_ips/?page=1",
|
||||
"last":"http://example.com/v2/floating_ips/?page=3",
|
||||
"first":"http://example.com/v2/floating_ips/?page=1"
|
||||
}
|
||||
}
|
||||
"links":[]
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/floating_ips/192.168.0.1/actions", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -158,10 +149,8 @@ func TestFloatingIPsActions_ListPageByNumber(t *testing.T) {
|
|||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.FloatingIPActions.List(ctx, "192.168.0.1", opt)
|
||||
_, _, err := client.FloatingIPActions.List(ctx, "192.168.0.1", opt)
|
||||
if err != nil {
|
||||
t.Errorf("FloatingIPsActions.List returned error: %v", err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
|
|
@ -44,15 +44,13 @@ func TestFloatingIPs_ListFloatingIPsMultiplePages(t *testing.T) {
|
|||
|
||||
mux.HandleFunc("/v2/floating_ips", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
fmt.Fprint(w, `{"floating_ips": [{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"},{"region":{"slug":"nyc3"},"droplet":{"id":2},"ip":"192.168.0.2"}], "links":{"pages":{"next":"http://example.com/v2/floating_ips/?page=2"}}}`)
|
||||
fmt.Fprint(w, `{"floating_ips": [{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"},{"region":{"slug":"nyc3"},"droplet":{"id":2},"ip":"192.168.0.2"}], "links":[]}`)
|
||||
})
|
||||
|
||||
_, resp, err := client.FloatingIPs.List(ctx, nil)
|
||||
_, _, err := client.FloatingIPs.List(ctx, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestFloatingIPs_RetrievePageByNumber(t *testing.T) {
|
||||
|
@ -62,14 +60,7 @@ func TestFloatingIPs_RetrievePageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"floating_ips": [{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"},{"region":{"slug":"nyc3"},"droplet":{"id":2},"ip":"192.168.0.2"}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/floating_ips/?page=3",
|
||||
"prev":"http://example.com/v2/floating_ips/?page=1",
|
||||
"last":"http://example.com/v2/floating_ips/?page=3",
|
||||
"first":"http://example.com/v2/floating_ips/?page=1"
|
||||
}
|
||||
}
|
||||
"links":[]
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/floating_ips", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -78,12 +69,10 @@ func TestFloatingIPs_RetrievePageByNumber(t *testing.T) {
|
|||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.FloatingIPs.List(ctx, opt)
|
||||
_, _, err := client.FloatingIPs.List(ctx, opt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestFloatingIPs_Get(t *testing.T) {
|
||||
|
|
2
godo.go
2
godo.go
|
@ -121,7 +121,7 @@ type Response struct {
|
|||
|
||||
// Links that were returned with the response. These are parsed from
|
||||
// request body and not the header.
|
||||
Links *Links
|
||||
Links []*LinkAction
|
||||
|
||||
// Meta describes generic information about the response.
|
||||
Meta *Meta
|
||||
|
|
38
godo_test.go
38
godo_test.go
|
@ -601,44 +601,6 @@ func TestDo_rateLimit_errorResponse(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func checkCurrentPage(t *testing.T, resp *Response, expectedPage int) {
|
||||
links := resp.Links
|
||||
p, err := links.CurrentPage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if p != expectedPage {
|
||||
t.Fatalf("expected current page to be '%d', was '%d'", expectedPage, p)
|
||||
}
|
||||
}
|
||||
|
||||
func checkNextPageToken(t *testing.T, resp *Response, expectedNextPageToken string) {
|
||||
t.Helper()
|
||||
links := resp.Links
|
||||
pageToken, err := links.NextPageToken()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if pageToken != expectedNextPageToken {
|
||||
t.Fatalf("expected next page token to be '%s', was '%s'", expectedNextPageToken, pageToken)
|
||||
}
|
||||
}
|
||||
|
||||
func checkPreviousPageToken(t *testing.T, resp *Response, expectedPreviousPageToken string) {
|
||||
t.Helper()
|
||||
links := resp.Links
|
||||
pageToken, err := links.PrevPageToken()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if pageToken != expectedPreviousPageToken {
|
||||
t.Fatalf("expected previous page token to be '%s', was '%s'", expectedPreviousPageToken, pageToken)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDo_completion_callback(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
|
|
@ -73,7 +73,7 @@ type imageRoot struct {
|
|||
|
||||
type imagesRoot struct {
|
||||
Images []Image
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
|
@ -221,14 +221,13 @@ func TestImages_ListImagesMultiplePages(t *testing.T) {
|
|||
|
||||
mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
fmt.Fprint(w, `{"images": [{"id": "1"},{"id": "2"}], "links":{"pages":{"next":"http://example.com/v2/images/?page=2"}}}`)
|
||||
fmt.Fprint(w, `{"images": [{"id": "1"},{"id": "2"}], "links":[]}`)
|
||||
})
|
||||
|
||||
_, resp, err := client.Images.List(ctx, &ListOptions{Page: 2})
|
||||
_, _, err := client.Images.List(ctx, &ListOptions{Page: 2})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestImages_RetrievePageByNumber(t *testing.T) {
|
||||
|
@ -238,14 +237,7 @@ func TestImages_RetrievePageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"images": [{"id": "1"},{"id": "2"}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/images/?page=3",
|
||||
"prev":"http://example.com/v2/images/?page=1",
|
||||
"last":"http://example.com/v2/images/?page=3",
|
||||
"first":"http://example.com/v2/images/?page=1"
|
||||
}
|
||||
}
|
||||
"links":[]
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/images", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -254,12 +246,10 @@ func TestImages_RetrievePageByNumber(t *testing.T) {
|
|||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.Images.List(ctx, opt)
|
||||
_, _, err := client.Images.List(ctx, opt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestImages_GetImageByID(t *testing.T) {
|
||||
|
|
|
@ -32,7 +32,7 @@ var _ InvoicesService = &InvoicesServiceOp{}
|
|||
// Invoice represents a DigitalOcean Invoice
|
||||
type Invoice struct {
|
||||
InvoiceItems []InvoiceItem `json:"invoice_items"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ type InvoiceItem struct {
|
|||
type InvoiceList struct {
|
||||
Invoices []InvoiceListItem `json:"invoices"`
|
||||
InvoicePreview InvoiceListItem `json:"invoice_preview"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
2
keys.go
2
keys.go
|
@ -45,7 +45,7 @@ type KeyUpdateRequest struct {
|
|||
|
||||
type keysRoot struct {
|
||||
SSHKeys []Key `json:"ssh_keys"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
17
keys_test.go
17
keys_test.go
|
@ -51,14 +51,13 @@ func TestKeys_ListKeysMultiplePages(t *testing.T) {
|
|||
|
||||
mux.HandleFunc("/v2/account/keys", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
fmt.Fprint(w, `{"droplets": [{"id":"1"},{"id":"2"}], "links":{"pages":{"next":"http://example.com/v2/account/keys/?page=2"}}}`)
|
||||
fmt.Fprint(w, `{"droplets": [{"id":"1"},{"id":"2"}], "links":[]}`)
|
||||
})
|
||||
|
||||
_, resp, err := client.Keys.List(ctx, nil)
|
||||
_, _, err := client.Keys.List(ctx, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestKeys_RetrievePageByNumber(t *testing.T) {
|
||||
|
@ -68,14 +67,7 @@ func TestKeys_RetrievePageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"keys": [{"id":"1"},{"id":"2"}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/account/keys/?page=3",
|
||||
"prev":"http://example.com/v2/account/keys/?page=1",
|
||||
"last":"http://example.com/v2/account/keys/?page=3",
|
||||
"first":"http://example.com/v2/account/keys/?page=1"
|
||||
}
|
||||
}
|
||||
"links":[]
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/account/keys", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -84,11 +76,10 @@ func TestKeys_RetrievePageByNumber(t *testing.T) {
|
|||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.Keys.List(ctx, opt)
|
||||
_, _, err := client.Keys.List(ctx, opt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestKeys_GetByID(t *testing.T) {
|
||||
|
|
|
@ -482,7 +482,7 @@ type AssociatedResource struct {
|
|||
|
||||
type kubernetesClustersRoot struct {
|
||||
Clusters []*KubernetesCluster `json:"kubernetes_clusters,omitempty"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
@ -500,7 +500,7 @@ type kubernetesNodePoolRoot struct {
|
|||
|
||||
type kubernetesNodePoolsRoot struct {
|
||||
NodePools []*KubernetesNodePool `json:"node_pools,omitempty"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []LinkAction `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
type kubernetesUpgradesRoot struct {
|
||||
|
@ -872,7 +872,7 @@ func (svc *KubernetesServiceOp) DeleteNode(ctx context.Context, clusterID, poolI
|
|||
|
||||
type kubernetesOptionsRoot struct {
|
||||
Options *KubernetesOptions `json:"options,omitempty"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []LinkAction `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
// GetOptions returns options about the Kubernetes service, such as the versions available for
|
||||
|
|
|
@ -210,12 +210,7 @@ func TestKubernetesClusters_ListClusters(t *testing.T) {
|
|||
"updated_at": "2018-06-15T07:11:26Z"
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"next": "https://api.digitalocean.com/v2/kubernetes/clusters?page=2",
|
||||
"last": "https://api.digitalocean.com/v2/kubernetes/clusters?page=2"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 2
|
||||
}
|
||||
|
@ -231,12 +226,7 @@ func TestKubernetesClusters_ListClusters(t *testing.T) {
|
|||
assert.Equal(t, wantClusters, gotClusters)
|
||||
|
||||
gotRespLinks := resp.Links
|
||||
wantRespLinks := &Links{
|
||||
Pages: &Pages{
|
||||
Next: "https://api.digitalocean.com/v2/kubernetes/clusters?page=2",
|
||||
Last: "https://api.digitalocean.com/v2/kubernetes/clusters?page=2",
|
||||
},
|
||||
}
|
||||
wantRespLinks := []*LinkAction{}
|
||||
assert.Equal(t, wantRespLinks, gotRespLinks)
|
||||
|
||||
gotRespMeta := resp.Meta
|
||||
|
|
|
@ -66,9 +66,6 @@ func TestLinks_ParseFirst(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := &Response{Links: &links}
|
||||
checkCurrentPage(t, r, 1)
|
||||
|
||||
if links.IsLastPage() {
|
||||
t.Fatalf("shouldn't be last page")
|
||||
}
|
||||
|
@ -81,9 +78,6 @@ func TestLinks_ParseMiddle(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := &Response{Links: &links}
|
||||
checkCurrentPage(t, r, 2)
|
||||
|
||||
if links.IsLastPage() {
|
||||
t.Fatalf("shouldn't be last page")
|
||||
}
|
||||
|
@ -96,8 +90,6 @@ func TestLinks_ParseLast(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := &Response{Links: &links}
|
||||
checkCurrentPage(t, r, 3)
|
||||
if !links.IsLastPage() {
|
||||
t.Fatalf("expected last page")
|
||||
}
|
||||
|
@ -109,9 +101,6 @@ func TestLinks_ParseProjectsLast(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := &Response{Links: &links}
|
||||
checkCurrentPage(t, r, 3)
|
||||
if !links.IsLastPage() {
|
||||
t.Fatalf("expected last page")
|
||||
}
|
||||
|
@ -123,9 +112,6 @@ func TestLinks_ParseMissing(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := &Response{Links: &links}
|
||||
checkCurrentPage(t, r, 1)
|
||||
}
|
||||
|
||||
func TestLinks_ParseURL(t *testing.T) {
|
||||
|
@ -210,47 +196,3 @@ func TestLinks_ParseEmptyString(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLinks_NextPageToken(t *testing.T) {
|
||||
t.Run("happy token", func(t *testing.T) {
|
||||
checkNextPageToken(t, &Response{Links: &Links{
|
||||
Pages: &Pages{
|
||||
Next: "https://api.digitalocean.com/v2/droplets/?page_token=aaa",
|
||||
},
|
||||
}}, "aaa")
|
||||
})
|
||||
t.Run("empty token", func(t *testing.T) {
|
||||
checkNextPageToken(t, &Response{Links: &Links{
|
||||
Pages: &Pages{
|
||||
Next: "https://api.digitalocean.com/v2/droplets/",
|
||||
},
|
||||
}}, "")
|
||||
})
|
||||
t.Run("no next page", func(t *testing.T) {
|
||||
checkNextPageToken(t, &Response{Links: &Links{
|
||||
Pages: &Pages{},
|
||||
}}, "")
|
||||
})
|
||||
}
|
||||
|
||||
func TestLinks_ParseNextPageToken(t *testing.T) {
|
||||
t.Run("happy token", func(t *testing.T) {
|
||||
checkPreviousPageToken(t, &Response{Links: &Links{
|
||||
Pages: &Pages{
|
||||
Prev: "https://api.digitalocean.com/v2/droplets/?page_token=aaa",
|
||||
},
|
||||
}}, "aaa")
|
||||
})
|
||||
t.Run("empty token", func(t *testing.T) {
|
||||
checkPreviousPageToken(t, &Response{Links: &Links{
|
||||
Pages: &Pages{
|
||||
Prev: "https://api.digitalocean.com/v2/droplets/",
|
||||
},
|
||||
}}, "")
|
||||
})
|
||||
t.Run("no next page", func(t *testing.T) {
|
||||
checkPreviousPageToken(t, &Response{Links: &Links{
|
||||
Pages: &Pages{},
|
||||
}}, "")
|
||||
})
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ func (l dropletIDsRequest) String() string {
|
|||
|
||||
type loadBalancersRoot struct {
|
||||
LoadBalancers []LoadBalancer `json:"load_balancers"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
|
@ -70,12 +70,7 @@ var lbListJSONResponse = `
|
|||
"disable_lets_encrypt_dns_records": true
|
||||
}
|
||||
],
|
||||
"links":{
|
||||
"pages":{
|
||||
"last":"http://localhost:3001/v2/load_balancers?page=3&per_page=1",
|
||||
"next":"http://localhost:3001/v2/load_balancers?page=2&per_page=1"
|
||||
}
|
||||
},
|
||||
"links":[],
|
||||
"meta":{
|
||||
"total":3
|
||||
}
|
||||
|
@ -756,12 +751,9 @@ func TestLoadBalancers_List_Pagination(t *testing.T) {
|
|||
})
|
||||
|
||||
opts := &ListOptions{Page: 2}
|
||||
_, resp, err := client.LoadBalancers.List(ctx, opts)
|
||||
_, _, err := client.LoadBalancers.List(ctx, opts)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "http://localhost:3001/v2/load_balancers?page=2&per_page=1", resp.Links.Pages.Next)
|
||||
assert.Equal(t, "http://localhost:3001/v2/load_balancers?page=3&per_page=1", resp.Links.Pages.Last)
|
||||
}
|
||||
|
||||
func TestLoadBalancers_Delete(t *testing.T) {
|
||||
|
|
|
@ -128,7 +128,7 @@ type AlertPolicyUpdateRequest struct {
|
|||
|
||||
type alertPoliciesRoot struct {
|
||||
AlertPolicies []AlertPolicy `json:"policies"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
|
@ -71,14 +71,7 @@ var (
|
|||
"enabled": false
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/monitoring/alerts/?page=3",
|
||||
"prev":"http://example.com/v2/monitoring/alerts/?page=1",
|
||||
"last":"http://example.com/v2/monitoring/alerts/?page=3",
|
||||
"first":"http://example.com/v2/monitoring/alerts/?page=1"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 2
|
||||
}
|
||||
|
@ -784,11 +777,10 @@ func TestAlertPolicies_ListPaging(t *testing.T) {
|
|||
fmt.Fprint(w, listPoliciesJSON)
|
||||
})
|
||||
|
||||
_, resp, err := client.Monitoring.ListAlertPolicies(ctx, nil)
|
||||
_, _, err := client.Monitoring.ListAlertPolicies(ctx, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Monitoring.ListAlertPolicies returned error: %v", err)
|
||||
}
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestAlertPolicy_Get(t *testing.T) {
|
||||
|
|
|
@ -124,7 +124,7 @@ type ProjectResourceLinks struct {
|
|||
|
||||
type projectsRoot struct {
|
||||
Projects []Project `json:"projects"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ type projectRoot struct {
|
|||
|
||||
type projectResourcesRoot struct {
|
||||
Resources []ProjectResource `json:"resources"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
|
@ -62,11 +62,7 @@ func TestProjects_ListWithMultiplePages(t *testing.T) {
|
|||
"name": "project-2"
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"next": "http://example.com/v2/projects?page=2"
|
||||
}
|
||||
}
|
||||
"links": []
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/projects", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -74,12 +70,10 @@ func TestProjects_ListWithMultiplePages(t *testing.T) {
|
|||
fmt.Fprint(w, mockResp)
|
||||
})
|
||||
|
||||
_, resp, err := client.Projects.List(ctx, nil)
|
||||
_, _, err := client.Projects.List(ctx, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Projects.List returned error: %v", err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestProjects_ListWithPageNumber(t *testing.T) {
|
||||
|
@ -98,14 +92,7 @@ func TestProjects_ListWithPageNumber(t *testing.T) {
|
|||
"name": "project-2"
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"next": "http://example.com/v2/projects?page=3",
|
||||
"prev": "http://example.com/v2/projects?page=1",
|
||||
"last": "http://example.com/v2/projects?page=3",
|
||||
"first": "http://example.com/v2/projects?page=1"
|
||||
}
|
||||
}
|
||||
"links": []
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/projects", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -113,12 +100,10 @@ func TestProjects_ListWithPageNumber(t *testing.T) {
|
|||
fmt.Fprint(w, mockResp)
|
||||
})
|
||||
|
||||
_, resp, err := client.Projects.List(ctx, &ListOptions{Page: 2})
|
||||
_, _, err := client.Projects.List(ctx, &ListOptions{Page: 2})
|
||||
if err != nil {
|
||||
t.Errorf("Projects.List returned error: %v", err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestProjects_GetDefault(t *testing.T) {
|
||||
|
@ -394,11 +379,7 @@ func TestProjects_ListResourcesWithMultiplePages(t *testing.T) {
|
|||
}
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"next": "http://example.com/v2/projects/project-1/resources?page=2"
|
||||
}
|
||||
}
|
||||
"links": []
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/projects/project-1/resources", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -406,12 +387,10 @@ func TestProjects_ListResourcesWithMultiplePages(t *testing.T) {
|
|||
fmt.Fprint(w, mockResp)
|
||||
})
|
||||
|
||||
_, resp, err := client.Projects.ListResources(ctx, "project-1", nil)
|
||||
_, _, err := client.Projects.ListResources(ctx, "project-1", nil)
|
||||
if err != nil {
|
||||
t.Errorf("Projects.ListResources returned error: %v", err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestProjects_ListResourcesWithPageNumber(t *testing.T) {
|
||||
|
@ -443,14 +422,7 @@ func TestProjects_ListResourcesWithPageNumber(t *testing.T) {
|
|||
}
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"next": "http://example.com/v2/projects/project-1/resources?page=3",
|
||||
"prev": "http://example.com/v2/projects/project-1/resources?page=1",
|
||||
"last": "http://example.com/v2/projects/project-1/resources?page=3",
|
||||
"first": "http://example.com/v2/projects/project-1/resources?page=1"
|
||||
}
|
||||
}
|
||||
"links": []
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/projects/project-1/resources", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -458,12 +430,10 @@ func TestProjects_ListResourcesWithPageNumber(t *testing.T) {
|
|||
fmt.Fprint(w, mockResp)
|
||||
})
|
||||
|
||||
_, resp, err := client.Projects.ListResources(ctx, "project-1", &ListOptions{Page: 2})
|
||||
_, _, err := client.Projects.ListResources(ctx, "project-1", &ListOptions{Page: 2})
|
||||
if err != nil {
|
||||
t.Errorf("Projects.ListResources returned error: %v", err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestProjects_AssignFleetResourcesWithTypes(t *testing.T) {
|
||||
|
|
|
@ -31,7 +31,7 @@ type Region struct {
|
|||
|
||||
type regionsRoot struct {
|
||||
Regions []Region
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
|
@ -50,15 +50,13 @@ func TestRegions_ListRegionsMultiplePages(t *testing.T) {
|
|||
|
||||
mux.HandleFunc("/v2/regions", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
fmt.Fprint(w, `{"regions": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/regions/?page=2"}}}`)
|
||||
fmt.Fprint(w, `{"regions": [{"id":1},{"id":2}], "links":[]}`)
|
||||
})
|
||||
|
||||
_, resp, err := client.Regions.List(ctx, nil)
|
||||
_, _, err := client.Regions.List(ctx, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestRegions_RetrievePageByNumber(t *testing.T) {
|
||||
|
@ -68,14 +66,7 @@ func TestRegions_RetrievePageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"regions": [{"id":1},{"id":2}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/regions/?page=3",
|
||||
"prev":"http://example.com/v2/regions/?page=1",
|
||||
"last":"http://example.com/v2/regions/?page=3",
|
||||
"first":"http://example.com/v2/regions/?page=1"
|
||||
}
|
||||
}
|
||||
"links":[]
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/regions", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -84,12 +75,10 @@ func TestRegions_RetrievePageByNumber(t *testing.T) {
|
|||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.Regions.List(ctx, opt)
|
||||
_, _, err := client.Regions.List(ctx, opt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestRegion_String(t *testing.T) {
|
||||
|
|
10
registry.go
10
registry.go
|
@ -121,25 +121,25 @@ type registryRoot struct {
|
|||
|
||||
type repositoriesRoot struct {
|
||||
Repositories []*Repository `json:"repositories,omitempty"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type repositoriesV2Root struct {
|
||||
Repositories []*RepositoryV2 `json:"repositories,omitempty"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type repositoryTagsRoot struct {
|
||||
Tags []*RepositoryTag `json:"tags,omitempty"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type repositoryManifestsRoot struct {
|
||||
Manifests []*RepositoryManifest `json:"manifests,omitempty"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ type garbageCollectionRoot struct {
|
|||
|
||||
type garbageCollectionsRoot struct {
|
||||
GarbageCollections []*GarbageCollection `json:"garbage_collections,omitempty"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
|
@ -235,12 +235,7 @@ func TestRepository_List(t *testing.T) {
|
|||
}
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"next": "https://api.digitalocean.com/v2/registry/` + testRegistry + `/repositories?page=2",
|
||||
"last": "https://api.digitalocean.com/v2/registry/` + testRegistry + `/repositories?page=2"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 2
|
||||
}
|
||||
|
@ -256,12 +251,7 @@ func TestRepository_List(t *testing.T) {
|
|||
require.Equal(t, wantRepositories, got)
|
||||
|
||||
gotRespLinks := response.Links
|
||||
wantRespLinks := &Links{
|
||||
Pages: &Pages{
|
||||
Next: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositories?page=2", testRegistry),
|
||||
Last: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositories?page=2", testRegistry),
|
||||
},
|
||||
}
|
||||
wantRespLinks := []*LinkAction{}
|
||||
assert.Equal(t, wantRespLinks, gotRespLinks)
|
||||
|
||||
gotRespMeta := response.Meta
|
||||
|
@ -302,7 +292,6 @@ func TestRepository_ListV2(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
baseLinkPage := fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositoriesV2", testRegistry)
|
||||
getResponseJSON := `{
|
||||
"repositories": [
|
||||
{
|
||||
|
@ -334,14 +323,7 @@ func TestRepository_ListV2(t *testing.T) {
|
|||
}
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"first": "` + baseLinkPage + `?page=1&page_size=1",
|
||||
"prev": "` + baseLinkPage + `?page=2&page_size=1&page_token=aaa",
|
||||
"next": "` + baseLinkPage + `?page=4&page_size=1&page_token=ccc",
|
||||
"last": "` + baseLinkPage + `?page=5&page_size=1"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 5
|
||||
}
|
||||
|
@ -357,14 +339,7 @@ func TestRepository_ListV2(t *testing.T) {
|
|||
require.Equal(t, wantRepositories, got)
|
||||
|
||||
gotRespLinks := response.Links
|
||||
wantRespLinks := &Links{
|
||||
Pages: &Pages{
|
||||
First: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositoriesV2?page=1&page_size=1", testRegistry),
|
||||
Prev: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositoriesV2?page=2&page_size=1&page_token=aaa", testRegistry),
|
||||
Next: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositoriesV2?page=4&page_size=1&page_token=ccc", testRegistry),
|
||||
Last: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositoriesV2?page=5&page_size=1", testRegistry),
|
||||
},
|
||||
}
|
||||
wantRespLinks := []*LinkAction{}
|
||||
assert.Equal(t, wantRespLinks, gotRespLinks)
|
||||
|
||||
gotRespMeta := response.Meta
|
||||
|
@ -401,12 +376,7 @@ func TestRepository_ListTags(t *testing.T) {
|
|||
"updated_at": "` + testTimeString + `"
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"next": "https://api.digitalocean.com/v2/registry/` + testRegistry + `/repositories/` + testEncodedRepository + `/tags?page=2",
|
||||
"last": "https://api.digitalocean.com/v2/registry/` + testRegistry + `/repositories/` + testEncodedRepository + `/tags?page=2"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 2
|
||||
}
|
||||
|
@ -422,12 +392,7 @@ func TestRepository_ListTags(t *testing.T) {
|
|||
require.Equal(t, wantTags, got)
|
||||
|
||||
gotRespLinks := response.Links
|
||||
wantRespLinks := &Links{
|
||||
Pages: &Pages{
|
||||
Next: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositories/%s/tags?page=2", testRegistry, testEncodedRepository),
|
||||
Last: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositories/%s/tags?page=2", testRegistry, testEncodedRepository),
|
||||
},
|
||||
}
|
||||
wantRespLinks := []*LinkAction{}
|
||||
assert.Equal(t, wantRespLinks, gotRespLinks)
|
||||
|
||||
gotRespMeta := response.Meta
|
||||
|
@ -497,14 +462,7 @@ func TestRegistry_ListManifests(t *testing.T) {
|
|||
]
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"first": "https://api.digitalocean.com/v2/registry/` + testRegistry + `/repositories/` + testEncodedRepository + `/digests?page=1&page_size=1",
|
||||
"prev": "https://api.digitalocean.com/v2/registry/` + testRegistry + `/repositories/` + testEncodedRepository + `/digests?page=2&page_size=1",
|
||||
"next": "https://api.digitalocean.com/v2/registry/` + testRegistry + `/repositories/` + testEncodedRepository + `/digests?page=4&page_size=1",
|
||||
"last": "https://api.digitalocean.com/v2/registry/` + testRegistry + `/repositories/` + testEncodedRepository + `/digests?page=5&page_size=1"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 5
|
||||
}
|
||||
|
@ -520,14 +478,7 @@ func TestRegistry_ListManifests(t *testing.T) {
|
|||
require.Equal(t, wantTags, got)
|
||||
|
||||
gotRespLinks := response.Links
|
||||
wantRespLinks := &Links{
|
||||
Pages: &Pages{
|
||||
First: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositories/%s/digests?page=1&page_size=1", testRegistry, testEncodedRepository),
|
||||
Prev: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositories/%s/digests?page=2&page_size=1", testRegistry, testEncodedRepository),
|
||||
Next: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositories/%s/digests?page=4&page_size=1", testRegistry, testEncodedRepository),
|
||||
Last: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/repositories/%s/digests?page=5&page_size=1", testRegistry, testEncodedRepository),
|
||||
},
|
||||
}
|
||||
wantRespLinks := []*LinkAction{}
|
||||
assert.Equal(t, wantRespLinks, gotRespLinks)
|
||||
|
||||
gotRespMeta := response.Meta
|
||||
|
@ -651,12 +602,7 @@ func TestGarbageCollection_List(t *testing.T) {
|
|||
"freed_bytes": {{.FreedBytes}}
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"next": "https://api.digitalocean.com/v2/registry/` + testRegistry + `/garbage-collections?page=2",
|
||||
"last": "https://api.digitalocean.com/v2/registry/` + testRegistry + `/garbage-collections?page=2"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 2
|
||||
}
|
||||
|
@ -675,12 +621,7 @@ func TestGarbageCollection_List(t *testing.T) {
|
|||
require.Equal(t, want, got)
|
||||
|
||||
gotRespLinks := resp.Links
|
||||
wantRespLinks := &Links{
|
||||
Pages: &Pages{
|
||||
Next: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/garbage-collections?page=2", testRegistry),
|
||||
Last: fmt.Sprintf("https://api.digitalocean.com/v2/registry/%s/garbage-collections?page=2", testRegistry),
|
||||
},
|
||||
}
|
||||
wantRespLinks := []*LinkAction{}
|
||||
assert.Equal(t, wantRespLinks, gotRespLinks)
|
||||
|
||||
gotRespMeta := resp.Meta
|
||||
|
|
|
@ -45,13 +45,13 @@ func (f ReservedIP) URN() string {
|
|||
|
||||
type reservedIPsRoot struct {
|
||||
ReservedIPs []ReservedIP `json:"reserved_ips"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type reservedIPRoot struct {
|
||||
ReservedIP *ReservedIP `json:"reserved_ip"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
// ReservedIPCreateRequest represents a request to create a reserved IP.
|
||||
|
|
|
@ -124,15 +124,13 @@ func TestReservedIPsActions_ListMultiplePages(t *testing.T) {
|
|||
|
||||
mux.HandleFunc("/v2/reserved_ips/192.168.0.1/actions", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
fmt.Fprint(w, `{"actions":[{"status":"in-progress"}], "links":{"pages":{"next":"http://example.com/v2/reserved_ips/192.168.0.1/actions?page=2"}}}`)
|
||||
fmt.Fprint(w, `{"actions":[{"status":"in-progress"}], "links":[]}`)
|
||||
})
|
||||
|
||||
_, resp, err := client.ReservedIPActions.List(ctx, "192.168.0.1", nil)
|
||||
_, _, err := client.ReservedIPActions.List(ctx, "192.168.0.1", nil)
|
||||
if err != nil {
|
||||
t.Errorf("ReservedIPsActions.List returned error: %v", err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestReservedIPsActions_ListPageByNumber(t *testing.T) {
|
||||
|
@ -142,14 +140,7 @@ func TestReservedIPsActions_ListPageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"actions":[{"status":"in-progress"}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/reserved_ips/?page=3",
|
||||
"prev":"http://example.com/v2/reserved_ips/?page=1",
|
||||
"last":"http://example.com/v2/reserved_ips/?page=3",
|
||||
"first":"http://example.com/v2/reserved_ips/?page=1"
|
||||
}
|
||||
}
|
||||
"links":[]
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/reserved_ips/192.168.0.1/actions", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -158,10 +149,8 @@ func TestReservedIPsActions_ListPageByNumber(t *testing.T) {
|
|||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.ReservedIPActions.List(ctx, "192.168.0.1", opt)
|
||||
_, _, err := client.ReservedIPActions.List(ctx, "192.168.0.1", opt)
|
||||
if err != nil {
|
||||
t.Errorf("ReservedIPsActions.List returned error: %v", err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
|
|
@ -44,15 +44,13 @@ func TestReservedIPs_ListReservedIPsMultiplePages(t *testing.T) {
|
|||
|
||||
mux.HandleFunc("/v2/reserved_ips", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
fmt.Fprint(w, `{"reserved_ips": [{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"},{"region":{"slug":"nyc3"},"droplet":{"id":2},"ip":"192.168.0.2"}], "links":{"pages":{"next":"http://example.com/v2/reserved_ips/?page=2"}}}`)
|
||||
fmt.Fprint(w, `{"reserved_ips": [{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"},{"region":{"slug":"nyc3"},"droplet":{"id":2},"ip":"192.168.0.2"}], "links":[]}`)
|
||||
})
|
||||
|
||||
_, resp, err := client.ReservedIPs.List(ctx, nil)
|
||||
_, _, err := client.ReservedIPs.List(ctx, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestReservedIPs_RetrievePageByNumber(t *testing.T) {
|
||||
|
@ -62,14 +60,7 @@ func TestReservedIPs_RetrievePageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"reserved_ips": [{"region":{"slug":"nyc3"},"droplet":{"id":1},"ip":"192.168.0.1"},{"region":{"slug":"nyc3"},"droplet":{"id":2},"ip":"192.168.0.2"}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/reserved_ips/?page=3",
|
||||
"prev":"http://example.com/v2/reserved_ips/?page=1",
|
||||
"last":"http://example.com/v2/reserved_ips/?page=3",
|
||||
"first":"http://example.com/v2/reserved_ips/?page=1"
|
||||
}
|
||||
}
|
||||
"links":[]
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/reserved_ips", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -78,12 +69,10 @@ func TestReservedIPs_RetrievePageByNumber(t *testing.T) {
|
|||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.ReservedIPs.List(ctx, opt)
|
||||
_, _, err := client.ReservedIPs.List(ctx, opt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestReservedIPs_Get(t *testing.T) {
|
||||
|
|
2
sizes.go
2
sizes.go
|
@ -40,7 +40,7 @@ func (s Size) String() string {
|
|||
|
||||
type sizesRoot struct {
|
||||
Sizes []Size
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
|
@ -100,15 +100,13 @@ func TestSizes_ListSizesMultiplePages(t *testing.T) {
|
|||
|
||||
mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
fmt.Fprint(w, `{"sizes": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/sizes/?page=2"}}}`)
|
||||
fmt.Fprint(w, `{"sizes": [{"id":1},{"id":2}], "links":[]}`)
|
||||
})
|
||||
|
||||
_, resp, err := client.Sizes.List(ctx, nil)
|
||||
_, _, err := client.Sizes.List(ctx, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestSizes_RetrievePageByNumber(t *testing.T) {
|
||||
|
@ -118,14 +116,7 @@ func TestSizes_RetrievePageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"sizes": [{"id":1},{"id":2}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/sizes/?page=3",
|
||||
"prev":"http://example.com/v2/sizes/?page=1",
|
||||
"last":"http://example.com/v2/sizes/?page=3",
|
||||
"first":"http://example.com/v2/sizes/?page=1"
|
||||
}
|
||||
}
|
||||
"links":[]
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/sizes", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -134,12 +125,10 @@ func TestSizes_RetrievePageByNumber(t *testing.T) {
|
|||
})
|
||||
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.Sizes.List(ctx, opt)
|
||||
_, _, err := client.Sizes.List(ctx, opt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestSize_String(t *testing.T) {
|
||||
|
|
|
@ -46,7 +46,7 @@ type snapshotRoot struct {
|
|||
|
||||
type snapshotsRoot struct {
|
||||
Snapshots []Snapshot `json:"snapshots"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
Meta *Meta `json:"meta,omitempty"`
|
||||
}
|
||||
|
||||
|
|
|
@ -87,15 +87,14 @@ func TestSnapshots_ListSnapshotsMultiplePages(t *testing.T) {
|
|||
|
||||
mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) {
|
||||
testMethod(t, r, http.MethodGet)
|
||||
fmt.Fprint(w, `{"snapshots": [{"id":"1"},{"id":"2"}], "links":{"pages":{"next":"http://example.com/v2/snapshots/?page=2"}}}`)
|
||||
fmt.Fprint(w, `{"snapshots": [{"id":"1"},{"id":"2"}], "links":[]}`)
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
_, resp, err := client.Snapshots.List(ctx, &ListOptions{Page: 2})
|
||||
_, _, err := client.Snapshots.List(ctx, &ListOptions{Page: 2})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
checkCurrentPage(t, resp, 1)
|
||||
}
|
||||
|
||||
func TestSnapshots_RetrievePageByNumber(t *testing.T) {
|
||||
|
@ -105,14 +104,7 @@ func TestSnapshots_RetrievePageByNumber(t *testing.T) {
|
|||
jBlob := `
|
||||
{
|
||||
"snapshots": [{"id":"1"},{"id":"2"}],
|
||||
"links":{
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/snapshots/?page=3",
|
||||
"prev":"http://example.com/v2/snapshots/?page=1",
|
||||
"last":"http://example.com/v2/snapshots/?page=3",
|
||||
"first":"http://example.com/v2/snapshots/?page=1"
|
||||
}
|
||||
}
|
||||
"links":[]
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/snapshots", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -122,12 +114,10 @@ func TestSnapshots_RetrievePageByNumber(t *testing.T) {
|
|||
|
||||
ctx := context.Background()
|
||||
opt := &ListOptions{Page: 2}
|
||||
_, resp, err := client.Snapshots.List(ctx, opt)
|
||||
_, _, err := client.Snapshots.List(ctx, opt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func TestSnapshots_GetSnapshotByID(t *testing.T) {
|
||||
|
|
|
@ -67,13 +67,13 @@ func (f Volume) URN() string {
|
|||
|
||||
type storageVolumesRoot struct {
|
||||
Volumes []Volume `json:"volumes"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type storageVolumeRoot struct {
|
||||
Volume *Volume `json:"volume"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
Links []*LinkAction `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
// VolumeCreateRequest represents a request to create a block store
|
||||
|
|
|
@ -42,12 +42,7 @@ func TestStorageVolumes_ListStorageVolumes(t *testing.T) {
|
|||
"tags": []
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"last": "https://api.digitalocean.com/v2/volumes?page=2",
|
||||
"next": "https://api.digitalocean.com/v2/volumes?page=2"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 28
|
||||
}
|
||||
|
@ -161,7 +156,7 @@ func TestStorageVolumes_ListVolumesByName(t *testing.T) {
|
|||
"tags": ["tag1", "tag2"]
|
||||
}
|
||||
],
|
||||
"links": {},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 1
|
||||
}
|
||||
|
@ -228,7 +223,7 @@ func TestStorageVolumes_ListVolumesByRegion(t *testing.T) {
|
|||
"tags": ["tag1", "tag2"]
|
||||
}
|
||||
],
|
||||
"links": {},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 1
|
||||
}
|
||||
|
@ -295,7 +290,7 @@ func TestStorageVolumes_ListVolumesByNameAndRegion(t *testing.T) {
|
|||
"tags": ["tag1", "tag2"]
|
||||
}
|
||||
],
|
||||
"links": {},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 1
|
||||
}
|
||||
|
@ -374,7 +369,7 @@ func TestStorageVolumes_Create(t *testing.T) {
|
|||
"created_at": "2002-10-02T15:00:00.05Z",
|
||||
"tags": ["tag1", "tag2"]
|
||||
},
|
||||
"links": {}
|
||||
"links": []
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/volumes", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -436,7 +431,7 @@ func TestStorageVolumes_CreateFormatted(t *testing.T) {
|
|||
"filesystem_label": "",
|
||||
"tags": ["tag1", "tag2"]
|
||||
},
|
||||
"links": {}
|
||||
"links": []
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/volumes", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -494,7 +489,7 @@ func TestStorageVolumes_CreateFromSnapshot(t *testing.T) {
|
|||
"created_at": "2002-10-02T15:00:00.05Z",
|
||||
"tags": ["tag1", "tag2"]
|
||||
},
|
||||
"links": {}
|
||||
"links": []
|
||||
}`
|
||||
|
||||
mux.HandleFunc("/v2/volumes", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -557,12 +552,7 @@ func TestStorageSnapshots_ListStorageSnapshots(t *testing.T) {
|
|||
"created_at": "2012-10-03T15:00:01.05Z"
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"last": "https://api.digitalocean.com/v2/volumes?page=2",
|
||||
"next": "https://api.digitalocean.com/v2/volumes?page=2"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 28
|
||||
}
|
||||
|
@ -669,12 +659,7 @@ func TestStorageSnapshots_Create(t *testing.T) {
|
|||
"created_at": "2002-10-02T15:00:00.05Z",
|
||||
"tags": ["one", "two"]
|
||||
},
|
||||
"links": {
|
||||
"pages": {
|
||||
"last": "https://api.digitalocean.com/v2/volumes/98d414c6-295e-4e3a-ac58-eb9456c1e1d1/snapshots?page=2",
|
||||
"next": "https://api.digitalocean.com/v2/volumes/98d414c6-295e-4e3a-ac58-eb9456c1e1d1/snapshots?page=2"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 28
|
||||
}
|
||||
|
|
2
tags.go
2
tags.go
|
@ -112,7 +112,7 @@ type UntagResourcesRequest struct {
|
|||
|
||||
type tagsRoot struct {
|
||||
Tags []Tag `json:"tags"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
12
tags_test.go
12
tags_test.go
|
@ -67,14 +67,7 @@ var (
|
|||
}
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"pages":{
|
||||
"next":"http://example.com/v2/tags/?page=3",
|
||||
"prev":"http://example.com/v2/tags/?page=1",
|
||||
"last":"http://example.com/v2/tags/?page=3",
|
||||
"first":"http://example.com/v2/tags/?page=1"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 2
|
||||
}
|
||||
|
@ -279,11 +272,10 @@ func TestTags_ListPaging(t *testing.T) {
|
|||
fmt.Fprint(w, listJSON)
|
||||
})
|
||||
|
||||
_, resp, err := client.Tags.List(ctx, nil)
|
||||
_, _, err := client.Tags.List(ctx, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Tags.List returned error: %v", err)
|
||||
}
|
||||
checkCurrentPage(t, resp, 2)
|
||||
}
|
||||
|
||||
func assertStringTagEqual(t *testing.T, tag string, compareTag, errorMessage string) {
|
||||
|
|
4
vpcs.go
4
vpcs.go
|
@ -94,13 +94,13 @@ type vpcRoot struct {
|
|||
|
||||
type vpcsRoot struct {
|
||||
VPCs []*VPC `json:"vpcs"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type vpcMembersRoot struct {
|
||||
Members []*VPCMember `json:"members"`
|
||||
Links *Links `json:"links"`
|
||||
Links []*LinkAction `json:"links"`
|
||||
Meta *Meta `json:"meta"`
|
||||
}
|
||||
|
||||
|
|
20
vpcs_test.go
20
vpcs_test.go
|
@ -71,12 +71,7 @@ func TestVPCs_List(t *testing.T) {
|
|||
want := []*VPC{
|
||||
vTestObj,
|
||||
}
|
||||
links := &Links{
|
||||
Pages: &Pages{
|
||||
Last: "http://localhost/v2/vpcs?page=3&per_page=1",
|
||||
Next: "http://localhost/v2/vpcs?page=2&per_page=1",
|
||||
},
|
||||
}
|
||||
links := []*LinkAction{}
|
||||
meta := &Meta{
|
||||
Total: 3,
|
||||
}
|
||||
|
@ -85,12 +80,7 @@ func TestVPCs_List(t *testing.T) {
|
|||
"vpcs": [
|
||||
` + vTestJSON + `
|
||||
],
|
||||
"links": {
|
||||
"pages": {
|
||||
"last": "http://localhost/v2/vpcs?page=3&per_page=1",
|
||||
"next": "http://localhost/v2/vpcs?page=2&per_page=1"
|
||||
}
|
||||
},
|
||||
"links": [],
|
||||
"meta": {"total": 3}
|
||||
}
|
||||
`
|
||||
|
@ -356,8 +346,7 @@ func TestVPCs_ListMembers(t *testing.T) {
|
|||
"created_at": "2020-03-13T19:30:48Z"
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 4
|
||||
}
|
||||
|
@ -397,8 +386,7 @@ func TestVPCs_ListMembers(t *testing.T) {
|
|||
"created_at": "2020-03-13T19:30:48Z"
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
},
|
||||
"links": [],
|
||||
"meta": {
|
||||
"total": 1
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue