Merge pull request #96211 from feiskyer/fix-paging-issue

Fix paging issues when Azure API returns empty values with non-empty nextLink
This commit is contained in:
Kubernetes Prow Robot 2020-11-05 09:25:59 -08:00 committed by GitHub
commit 2bb92efa3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 387 additions and 24 deletions

View File

@ -192,8 +192,14 @@ func (c *Client) listManagedCluster(ctx context.Context, resourceGroupName strin
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "managedcluster.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -373,6 +373,35 @@ func TestListWithListResponderError(t *testing.T) {
assert.Equal(t, 0, len(result))
}
func TestListWithNextPage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
resourceID := "/subscriptions/subscriptionID/resourceGroups/rg/providers/Microsoft.ContainerService/managedClusters"
armClient := mockarmclient.NewMockInterface(ctrl)
mcList := []containerservice.ManagedCluster{getTestManagedCluster("cluster"), getTestManagedCluster("cluster1"), getTestManagedCluster("cluster2")}
responseBody, err := json.Marshal(containerservice.ManagedClusterListResult{Value: &mcList, NextLink: to.StringPtr("nextLink")})
assert.NoError(t, err)
pagedResponse, err := json.Marshal(containerservice.ManagedClusterListResult{Value: &mcList})
assert.NoError(t, err)
armClient.EXPECT().PrepareGetRequest(gomock.Any(), gomock.Any()).Return(&http.Request{}, nil)
armClient.EXPECT().Send(gomock.Any(), gomock.Any()).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(pagedResponse)),
}, nil)
armClient.EXPECT().GetResource(gomock.Any(), resourceID, "").Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(responseBody)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(2)
mcClient := getTestManagedClusterClient(armClient)
result, rerr := mcClient.List(context.TODO(), "rg")
assert.Nil(t, rerr)
assert.Equal(t, 6, len(result))
}
func TestListNeverRateLimiter(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -192,8 +192,14 @@ func (c *Client) listDeployment(ctx context.Context, resourceGroupName string) (
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "deployment.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -371,6 +371,35 @@ func TestListWithListResponderError(t *testing.T) {
assert.Equal(t, 0, len(result))
}
func TestListWithNextPage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
resourceID := "/subscriptions/subscriptionID/resourceGroups/rg/providers/Microsoft.Resources/deployments"
armClient := mockarmclient.NewMockInterface(ctrl)
dpList := []resources.DeploymentExtended{getTestDeploymentExtended("dep"), getTestDeploymentExtended("dep1"), getTestDeploymentExtended("dep2")}
partialResponse, err := json.Marshal(resources.DeploymentListResult{Value: &dpList, NextLink: to.StringPtr("nextLink")})
assert.NoError(t, err)
pagedResponse, err := json.Marshal(resources.DeploymentListResult{Value: &dpList})
assert.NoError(t, err)
armClient.EXPECT().PrepareGetRequest(gomock.Any(), gomock.Any()).Return(&http.Request{}, nil)
armClient.EXPECT().Send(gomock.Any(), gomock.Any()).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(pagedResponse)),
}, nil)
armClient.EXPECT().GetResource(gomock.Any(), resourceID, "").Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(partialResponse)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(2)
dpClient := getTestDeploymentClient(armClient)
result, rerr := dpClient.List(context.TODO(), "rg")
assert.Nil(t, rerr)
assert.Equal(t, 6, len(result))
}
func TestListNeverRateLimiter(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -341,8 +341,14 @@ func (c *Client) ListByResourceGroup(ctx context.Context, resourceGroupName stri
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "disk.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -192,8 +192,14 @@ func (c *Client) listLB(ctx context.Context, resourceGroupName string) ([]networ
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "loadbalancer.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -165,6 +165,36 @@ func TestList(t *testing.T) {
assert.Equal(t, throttleErr, rerr)
}
func TestListWithNextPage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
resourceID := "/subscriptions/subscriptionID/resourceGroups/rg/providers/Microsoft.Network/loadBalancers"
armClient := mockarmclient.NewMockInterface(ctrl)
lbList := []network.LoadBalancer{getTestLoadBalancer("lb1"), getTestLoadBalancer("lb2"), getTestLoadBalancer("lb3")}
partialResponse, err := json.Marshal(network.LoadBalancerListResult{Value: &lbList, NextLink: to.StringPtr("nextLink")})
assert.NoError(t, err)
pagedResponse, err := json.Marshal(network.LoadBalancerListResult{Value: &lbList})
assert.NoError(t, err)
armClient.EXPECT().PrepareGetRequest(gomock.Any(), gomock.Any()).Return(&http.Request{}, nil)
armClient.EXPECT().Send(gomock.Any(), gomock.Any()).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(pagedResponse)),
}, nil)
armClient.EXPECT().GetResource(gomock.Any(), resourceID, "").Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(partialResponse)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(2)
lbClient := getTestLoadBalancerClient(armClient)
result, rerr := lbClient.List(context.TODO(), "rg")
assert.Nil(t, rerr)
assert.Equal(t, 6, len(result))
}
func TestListNextResultsMultiPages(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -265,8 +265,14 @@ func (c *Client) listPublicIPAddress(ctx context.Context, resourceGroupName stri
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "publicip.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -431,6 +431,35 @@ func TestListWithListResponderError(t *testing.T) {
assert.Equal(t, 0, len(result))
}
func TestListWithNextPage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
resourceID := "/subscriptions/subscriptionID/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses"
armClient := mockarmclient.NewMockInterface(ctrl)
pipList := []network.PublicIPAddress{getTestPublicIPAddress("pip1"), getTestPublicIPAddress("pip2"), getTestPublicIPAddress("pip3")}
partialResponse, err := json.Marshal(network.PublicIPAddressListResult{Value: &pipList, NextLink: to.StringPtr("nextLink")})
assert.NoError(t, err)
pagedResponse, err := json.Marshal(network.PublicIPAddressListResult{Value: &pipList})
assert.NoError(t, err)
armClient.EXPECT().PrepareGetRequest(gomock.Any(), gomock.Any()).Return(&http.Request{}, nil)
armClient.EXPECT().Send(gomock.Any(), gomock.Any()).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(pagedResponse)),
}, nil)
armClient.EXPECT().GetResource(gomock.Any(), resourceID, "").Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(partialResponse)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(2)
pipClient := getTestPublicIPAddressClient(armClient)
result, rerr := pipClient.List(context.TODO(), "rg")
assert.Nil(t, rerr)
assert.Equal(t, 6, len(result))
}
func TestListNeverRateLimiter(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -192,8 +192,14 @@ func (c *Client) listSecurityGroup(ctx context.Context, resourceGroupName string
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "securitygroup.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -331,6 +331,35 @@ func TestListWithListResponderError(t *testing.T) {
assert.Equal(t, 0, len(result))
}
func TestListWithNextPage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
resourceID := "/subscriptions/subscriptionID/resourceGroups/rg/providers/Microsoft.Network/networkSecurityGroups"
armClient := mockarmclient.NewMockInterface(ctrl)
nsgList := []network.SecurityGroup{getTestSecurityGroup("nsg1"), getTestSecurityGroup("nsg2"), getTestSecurityGroup("nsg3")}
partialResponse, err := json.Marshal(network.SecurityGroupListResult{Value: &nsgList, NextLink: to.StringPtr("nextLink")})
assert.NoError(t, err)
pagedResponse, err := json.Marshal(network.SecurityGroupListResult{Value: &nsgList})
assert.NoError(t, err)
armClient.EXPECT().PrepareGetRequest(gomock.Any(), gomock.Any()).Return(&http.Request{}, nil)
armClient.EXPECT().Send(gomock.Any(), gomock.Any()).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(pagedResponse)),
}, nil)
armClient.EXPECT().GetResource(gomock.Any(), resourceID, "").Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(partialResponse)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(2)
nsgClient := getTestSecurityGroupClient(armClient)
result, rerr := nsgClient.List(context.TODO(), "rg")
assert.Nil(t, rerr)
assert.Equal(t, 6, len(result))
}
func TestListNeverRateLimiter(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -303,8 +303,14 @@ func (c *Client) listSnapshotsByResourceGroup(ctx context.Context, resourceGroup
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "snapshot.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -295,6 +295,35 @@ func TestListByResourceGroupWithListResponderError(t *testing.T) {
assert.Equal(t, 0, len(result))
}
func TestListWithNextPage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
resourceID := "/subscriptions/subscriptionID/resourceGroups/rg/providers/Microsoft.Compute/snapshots"
armClient := mockarmclient.NewMockInterface(ctrl)
snList := []compute.Snapshot{getTestSnapshot("sn1"), getTestSnapshot("sn2"), getTestSnapshot("sn3")}
partialResponse, err := json.Marshal(compute.SnapshotList{Value: &snList, NextLink: to.StringPtr("nextLink")})
assert.NoError(t, err)
pagedResponse, err := json.Marshal(compute.SnapshotList{Value: &snList})
assert.NoError(t, err)
armClient.EXPECT().PrepareGetRequest(gomock.Any(), gomock.Any()).Return(&http.Request{}, nil)
armClient.EXPECT().Send(gomock.Any(), gomock.Any()).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(pagedResponse)),
}, nil)
armClient.EXPECT().GetResource(gomock.Any(), resourceID, "").Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(partialResponse)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(2)
snClient := getTestSnapshotClient(armClient)
result, rerr := snClient.ListByResourceGroup(context.TODO(), "rg")
assert.Nil(t, rerr)
assert.Equal(t, 6, len(result))
}
func TestListByResourceGroupNeverRateLimiter(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -364,8 +364,14 @@ func (c *Client) ListStorageAccountByResourceGroup(ctx context.Context, resource
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "storageAccount.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -197,8 +197,14 @@ func (c *Client) listSubnet(ctx context.Context, resourceGroupName string, virtu
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "subnet.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -305,6 +305,35 @@ func TestListWithListResponderError(t *testing.T) {
assert.Equal(t, 0, len(result))
}
func TestListWithNextPage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
resourceID := "/subscriptions/subscriptionID/resourceGroups/rg/providers/Microsoft.Network/virtualNetworks/vnet/subnets"
armClient := mockarmclient.NewMockInterface(ctrl)
subnetList := []network.Subnet{getTestSubnet("subnet1"), getTestSubnet("subnet2"), getTestSubnet("subnet3")}
partialResponse, err := json.Marshal(network.SubnetListResult{Value: &subnetList, NextLink: to.StringPtr("nextLink")})
assert.NoError(t, err)
pagedResponse, err := json.Marshal(network.SubnetListResult{Value: &subnetList})
assert.NoError(t, err)
armClient.EXPECT().PrepareGetRequest(gomock.Any(), gomock.Any()).Return(&http.Request{}, nil)
armClient.EXPECT().Send(gomock.Any(), gomock.Any()).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(pagedResponse)),
}, nil)
armClient.EXPECT().GetResource(gomock.Any(), resourceID, "").Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(partialResponse)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(2)
subnetClient := getTestSubnetClient(armClient)
result, rerr := subnetClient.List(context.TODO(), "rg", "vnet")
assert.Nil(t, rerr)
assert.Equal(t, 6, len(result))
}
func TestListNeverRateLimiter(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -194,8 +194,14 @@ func (c *Client) listVM(ctx context.Context, resourceGroupName string) ([]comput
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "vm.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -295,6 +295,35 @@ func TestListWithListResponderError(t *testing.T) {
assert.Equal(t, 0, len(result))
}
func TestListWithNextPage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
resourceID := "/subscriptions/subscriptionID/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines"
armClient := mockarmclient.NewMockInterface(ctrl)
vmList := []compute.VirtualMachine{getTestVM("vm1"), getTestVM("vm2"), getTestVM("vm3")}
partialResponse, err := json.Marshal(compute.VirtualMachineListResult{Value: &vmList, NextLink: to.StringPtr("nextLink")})
assert.NoError(t, err)
pagedResponse, err := json.Marshal(compute.VirtualMachineListResult{Value: &vmList})
assert.NoError(t, err)
armClient.EXPECT().PrepareGetRequest(gomock.Any(), gomock.Any()).Return(&http.Request{}, nil)
armClient.EXPECT().Send(gomock.Any(), gomock.Any()).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(pagedResponse)),
}, nil)
armClient.EXPECT().GetResource(gomock.Any(), resourceID, "").Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(partialResponse)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(2)
vmClient := getTestVMClient(armClient)
result, rerr := vmClient.List(context.TODO(), "rg")
assert.Nil(t, rerr)
assert.Equal(t, 6, len(result))
}
func TestListNeverRateLimiter(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -192,8 +192,14 @@ func (c *Client) listVMSS(ctx context.Context, resourceGroupName string) ([]comp
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "vmss.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -296,6 +296,35 @@ func TestListWithListResponderError(t *testing.T) {
assert.Equal(t, 0, len(result))
}
func TestListWithNextPage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
resourceID := "/subscriptions/subscriptionID/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets"
armClient := mockarmclient.NewMockInterface(ctrl)
vmssList := []compute.VirtualMachineScaleSet{getTestVMSS("vmss1"), getTestVMSS("vmss2"), getTestVMSS("vmss3")}
partialResponse, err := json.Marshal(compute.VirtualMachineScaleSetListResult{Value: &vmssList, NextLink: to.StringPtr("nextLink")})
assert.NoError(t, err)
pagedResponse, err := json.Marshal(compute.VirtualMachineScaleSetListResult{Value: &vmssList})
assert.NoError(t, err)
armClient.EXPECT().PrepareGetRequest(gomock.Any(), gomock.Any()).Return(&http.Request{}, nil)
armClient.EXPECT().Send(gomock.Any(), gomock.Any()).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(pagedResponse)),
}, nil)
armClient.EXPECT().GetResource(gomock.Any(), resourceID, "").Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(partialResponse)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(2)
vmssClient := getTestVMSSClient(armClient)
result, rerr := vmssClient.List(context.TODO(), "rg")
assert.Nil(t, rerr)
assert.Equal(t, 6, len(result))
}
func TestListNeverRateLimiter(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

View File

@ -198,8 +198,14 @@ func (c *Client) listVMSSVM(ctx context.Context, resourceGroupName string, virtu
return result, retry.GetError(resp, err)
}
for page.NotDone() {
result = append(result, *page.Response().Value...)
for {
result = append(result, page.Values()...)
// Abort the loop when there's no nextLink in the response.
if to.String(page.Response().NextLink) == "" {
break
}
if err = page.NextWithContext(ctx); err != nil {
klog.V(5).Infof("Received error in %s: resourceID: %s, error: %s", "vmssvm.list.next", resourceID, err)
return result, retry.GetError(page.Response().Response.Response, err)

View File

@ -295,6 +295,35 @@ func TestListWithListResponderError(t *testing.T) {
assert.Equal(t, 0, len(result))
}
func TestListWithNextPage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
resourceID := "/subscriptions/subscriptionID/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/vmss1/virtualMachines"
armClient := mockarmclient.NewMockInterface(ctrl)
vmssvmList := []compute.VirtualMachineScaleSetVM{getTestVMSSVM("vmss1", "1"), getTestVMSSVM("vmss1", "2"), getTestVMSSVM("vmss1", "3")}
partialResponse, err := json.Marshal(compute.VirtualMachineScaleSetVMListResult{Value: &vmssvmList, NextLink: to.StringPtr("nextLink")})
assert.NoError(t, err)
pagedResponse, err := json.Marshal(compute.VirtualMachineScaleSetVMListResult{Value: &vmssvmList})
assert.NoError(t, err)
armClient.EXPECT().PrepareGetRequest(gomock.Any(), gomock.Any()).Return(&http.Request{}, nil)
armClient.EXPECT().Send(gomock.Any(), gomock.Any()).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(pagedResponse)),
}, nil)
armClient.EXPECT().GetResource(gomock.Any(), resourceID, "InstanceView").Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(partialResponse)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(2)
vmssvmClient := getTestVMSSVMClient(armClient)
result, rerr := vmssvmClient.List(context.TODO(), "rg", "vmss1", "InstanceView")
assert.Nil(t, rerr)
assert.Equal(t, 6, len(result))
}
func TestListNeverRateLimiter(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()