Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanad committed Jul 6, 2020
1 parent fe8b90e commit 05236b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 8 additions & 0 deletions cluster-autoscaler/cloudprovider/azure/azure_fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ func (client *VirtualMachineScaleSetsClientMock) DeleteInstances(ctx context.Con
return nil
}

// DeleteInstancesAsync deletes a set of instances for specified VirtualMachineScaleSet and returns the future
func (client *VirtualMachineScaleSetsClientMock) DeleteInstancesAsync(ctx context.Context, resourceGroupName string, vmScaleSetName string, vmInstanceIDs compute.VirtualMachineScaleSetVMInstanceRequiredIDs) (*azure.Future, *retry.Error) {
client.mutex.Lock()
defer client.mutex.Unlock()
client.Called(resourceGroupName, vmScaleSetName, vmInstanceIDs)
return nil, nil
}

// List gets a list of VirtualMachineScaleSets.
func (client *VirtualMachineScaleSetsClientMock) List(ctx context.Context, resourceGroupName string) (result []compute.VirtualMachineScaleSet, rerr *retry.Error) {
client.mutex.Lock()
Expand Down
13 changes: 5 additions & 8 deletions cluster-autoscaler/cloudprovider/azure/azure_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ func TestTargetSize(t *testing.T) {
assert.True(t, registered)
assert.Equal(t, len(provider.NodeGroups()), 1)

ng := provider.NodeGroups()[0]
size, err := ng.TargetSize()
println(size)
targetSize, err := provider.NodeGroups()[0].TargetSize()
assert.NoError(t, err)
assert.Equal(t, 3, targetSize)
Expand Down Expand Up @@ -183,7 +180,7 @@ func TestDeleteNodes(t *testing.T) {
Status: "OK",
},
}
scaleSetClient.On("DeleteInstances", mock.Anything, "test-asg", mock.Anything, mock.Anything).Return(response, nil)
scaleSetClient.On("DeleteInstancesAsync", mock.Anything, "test-asg", mock.Anything, mock.Anything).Return(response, nil)
manager.azClient.virtualMachineScaleSetsClient = scaleSetClient
// TODO: this should call manager.Refresh() once the fetchAutoASG
// logic is refactored out
Expand Down Expand Up @@ -223,7 +220,7 @@ func TestDeleteNodes(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 2, targetSize)

scaleSetClient.AssertNumberOfCalls(t, "DeleteInstances", 1)
scaleSetClient.AssertNumberOfCalls(t, "DeleteInstancesAsync", 1)
}

func TestDeleteNoConflictRequest(t *testing.T) {
Expand Down Expand Up @@ -265,7 +262,7 @@ func TestDeleteNoConflictRequest(t *testing.T) {
},
}

scaleSetClient.On("DeleteInstances", mock.Anything, "test-asg", mock.Anything, mock.Anything).Return(response, nil)
scaleSetClient.On("DeleteInstancesAsync", mock.Anything, "test-asg", mock.Anything, mock.Anything).Return(response, nil)
manager.azClient.virtualMachineScaleSetsClient = scaleSetClient
manager.azClient.virtualMachineScaleSetVMsClient = vmsClient

Expand All @@ -288,8 +285,8 @@ func TestDeleteNoConflictRequest(t *testing.T) {
assert.True(t, ok)

err = scaleSet.DeleteNodes([]*apiv1.Node{node})
// ensure that DeleteInstances isn't called
scaleSetClient.AssertNumberOfCalls(t, "DeleteInstances", 0)
// ensure that DeleteInstancesAsync isn't called
scaleSetClient.AssertNumberOfCalls(t, "DeleteInstancesAsync", 0)
}

func TestId(t *testing.T) {
Expand Down

0 comments on commit 05236b9

Please sign in to comment.