Skip to content

Commit 9dadf37

Browse files
authored
Subnets: add query params to the List method (#77)
Allow to get detailed list of subnets, update unit tests.
1 parent 5658259 commit 9dadf37

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

selvpcclient/resell/v2/subnets/requests.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,17 @@ func Get(ctx context.Context, client *selvpcclient.ServiceClient, id string) (*S
3535
}
3636

3737
// List gets a list of subnets in the current domain.
38-
func List(ctx context.Context, client *selvpcclient.ServiceClient) ([]*Subnet, *selvpcclient.ResponseResult, error) {
38+
func List(ctx context.Context, client *selvpcclient.ServiceClient, opts ListOpts) ([]*Subnet, *selvpcclient.ResponseResult, error) {
3939
url := strings.Join([]string{client.Endpoint, resourceURL}, "/")
40+
41+
queryParams, err := selvpcclient.BuildQueryParameters(opts)
42+
if err != nil {
43+
return nil, nil, err
44+
}
45+
if queryParams != "" {
46+
url = strings.Join([]string{url, queryParams}, "?")
47+
}
48+
4049
responseResult, err := client.DoRequest(ctx, "GET", url, nil)
4150
if err != nil {
4251
return nil, nil, err

selvpcclient/resell/v2/subnets/requests_opts.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ type SubnetOpt struct {
2222
// PrefixLength represents length of the subnet prefix.
2323
PrefixLength int `json:"prefix_length"`
2424
}
25+
26+
// ListOpts represents options for the licenses List request.
27+
type ListOpts struct {
28+
Detailed bool `param:"detailed"`
29+
}

selvpcclient/resell/v2/subnets/testing/requests_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestListSubnets(t *testing.T) {
114114
TestListSubnetsResponseRaw, http.MethodGet, http.StatusOK, &endpointCalled, t)
115115

116116
ctx := context.Background()
117-
actual, _, err := subnets.List(ctx, testEnv.Client)
117+
actual, _, err := subnets.List(ctx, testEnv.Client, subnets.ListOpts{})
118118
if err != nil {
119119
t.Fatal(err)
120120
}
@@ -144,7 +144,7 @@ func TestListSubnetsSingle(t *testing.T) {
144144
TestListSubnetsSingleResponseRaw, http.MethodGet, http.StatusOK, &endpointCalled, t)
145145

146146
ctx := context.Background()
147-
actual, _, err := subnets.List(ctx, testEnv.Client)
147+
actual, _, err := subnets.List(ctx, testEnv.Client, subnets.ListOpts{})
148148
if err != nil {
149149
t.Fatal(err)
150150
}
@@ -170,7 +170,7 @@ func TestListSubnetsHTTPError(t *testing.T) {
170170
&endpointCalled, t)
171171

172172
ctx := context.Background()
173-
allSubnet, httpResponse, err := subnets.List(ctx, testEnv.Client)
173+
allSubnet, httpResponse, err := subnets.List(ctx, testEnv.Client, subnets.ListOpts{})
174174

175175
if !endpointCalled {
176176
t.Fatal("endpoint wasn't called")
@@ -194,7 +194,7 @@ func TestListSubnetsTimeoutError(t *testing.T) {
194194
testEnv.NewTestResellV2Client()
195195

196196
ctx := context.Background()
197-
allSubnet, _, err := subnets.List(ctx, testEnv.Client)
197+
allSubnet, _, err := subnets.List(ctx, testEnv.Client, subnets.ListOpts{})
198198

199199
if allSubnet != nil {
200200
t.Fatal("expected no subnets from the List method")
@@ -215,7 +215,7 @@ func TestListSubnetsUnmarshalError(t *testing.T) {
215215
&endpointCalled, t)
216216

217217
ctx := context.Background()
218-
allSubnet, _, err := subnets.List(ctx, testEnv.Client)
218+
allSubnet, _, err := subnets.List(ctx, testEnv.Client, subnets.ListOpts{})
219219

220220
if !endpointCalled {
221221
t.Fatal("endpoint wasn't called")

0 commit comments

Comments
 (0)