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

Instances : ListPrivateNetworks missing paging ability #140

Merged
merged 3 commits into from
May 4, 2021
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
11 changes: 9 additions & 2 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type InstanceService interface {
GetBandwidth(ctx context.Context, instanceID string) (*Bandwidth, error)
GetNeighbors(ctx context.Context, instanceID string) (*Neighbors, error)

ListPrivateNetworks(ctx context.Context, instanceID string) ([]PrivateNetwork, *Meta, error)
ListPrivateNetworks(ctx context.Context, instanceID string, options *ListOptions) ([]PrivateNetwork, *Meta, error)
AttachPrivateNetwork(ctx context.Context, instanceID, networkID string) error
DetachPrivateNetwork(ctx context.Context, instanceID, networkID string) error

Expand Down Expand Up @@ -459,13 +459,20 @@ func (i *InstanceServiceHandler) GetNeighbors(ctx context.Context, instanceID st
}

// ListPrivateNetworks currently attached to an instance.
func (i *InstanceServiceHandler) ListPrivateNetworks(ctx context.Context, instanceID string) ([]PrivateNetwork, *Meta, error) {
func (i *InstanceServiceHandler) ListPrivateNetworks(ctx context.Context, instanceID string, options *ListOptions) ([]PrivateNetwork, *Meta, error) {
uri := fmt.Sprintf("%s/%s/private-networks", instancePath, instanceID)
req, err := i.client.NewRequest(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, nil, err
}

newValues, err := query.Values(options)
if err != nil {
return nil, nil, err
}

req.URL.RawQuery = newValues.Encode()

networks := new(privateNetworksBase)
if err = i.client.DoWithContext(ctx, req, networks); err != nil {
return nil, nil, err
Expand Down
6 changes: 5 additions & 1 deletion instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ func TestServerServiceHandler_ListPrivateNetworks(t *testing.T) {
fmt.Fprint(writer, response)
})

privateNetwork, meta, err := client.Instance.ListPrivateNetworks(ctx, "14b3e7d6-ffb5-4994-8502-57fcd9db3b33")
options := &ListOptions{
PerPage: 1,
Cursor: "",
}
privateNetwork, meta, err := client.Instance.ListPrivateNetworks(ctx, "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", options)
if err != nil {
t.Errorf("Instance.ListPrivateNetworks return %+v, ", err)
}
Expand Down