@@ -19,21 +19,18 @@ package azure
1919import (
2020 "testing"
2121
22- "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
22+ apiv1 "k8s.io/api/core/v1"
23+ "k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
24+ "k8s.io/legacy-cloud-providers/azure/clients/vmssclient/mockvmssclient"
25+ "k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient/mockvmssvmclient"
26+
2327 "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2017-05-10/resources"
2428 "github.com/Azure/go-autorest/autorest/azure"
25- "github.com/Azure/go-autorest/autorest/to "
29+ "github.com/golang/mock/gomock "
2630 "github.com/stretchr/testify/assert"
27-
28- apiv1 "k8s.io/api/core/v1"
29- "k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
3031)
3132
3233func newTestAzureManager (t * testing.T ) * AzureManager {
33- vmssName := "test-asg"
34- skuName := "Standard_D4_v2"
35- location := "eastus"
36- var vmssCapacity int64 = 3
3734 manager := & AzureManager {
3835 env : azure .PublicCloud ,
3936 explicitlyConfigured : make (map [string ]bool ),
@@ -44,43 +41,9 @@ func newTestAzureManager(t *testing.T) *AzureManager {
4441 },
4542
4643 azClient : & azClient {
47- disksClient : & DisksClientMock {},
48- interfacesClient : & InterfacesClientMock {},
49- storageAccountsClient : & AccountsClientMock {},
5044 deploymentsClient : & DeploymentsClientMock {
5145 FakeStore : make (map [string ]resources.DeploymentExtended ),
5246 },
53- virtualMachinesClient : & VirtualMachinesClientMock {
54- FakeStore : make (map [string ]map [string ]compute.VirtualMachine ),
55- },
56- virtualMachineScaleSetsClient : & VirtualMachineScaleSetsClientMock {
57- FakeStore : map [string ]map [string ]compute.VirtualMachineScaleSet {
58- "test" : {
59- "test-asg" : {
60- Name : & vmssName ,
61- Sku : & compute.Sku {
62- Capacity : & vmssCapacity ,
63- Name : & skuName ,
64- },
65- VirtualMachineScaleSetProperties : & compute.VirtualMachineScaleSetProperties {},
66- Location : & location ,
67- },
68- },
69- },
70- },
71- virtualMachineScaleSetVMsClient : & VirtualMachineScaleSetVMsClientMock {
72- FakeStore : map [string ]map [string ]compute.VirtualMachineScaleSetVM {
73- "test" : {
74- "0" : {
75- ID : to .StringPtr (fakeVirtualMachineScaleSetVMID ),
76- InstanceID : to .StringPtr ("0" ),
77- VirtualMachineScaleSetVMProperties : & compute.VirtualMachineScaleSetVMProperties {
78- VMID : to .StringPtr ("123E4567-E89B-12D3-A456-426655440000" ),
79- },
80- },
81- },
82- },
83- },
8447 },
8548 }
8649
@@ -128,7 +91,20 @@ func TestNodeGroups(t *testing.T) {
12891}
12992
13093func TestNodeGroupForNode (t * testing.T ) {
94+ ctrl := gomock .NewController (t )
95+ defer ctrl .Finish ()
96+
97+ expectedVMSSVMs := newTestVMSSVMList ()
98+ expectedScaleSets := newTestVMSSList (3 , "test-asg" , "eastus" )
99+
131100 provider := newTestProvider (t )
101+ mockVMSSClient := mockvmssclient .NewMockInterface (ctrl )
102+ mockVMSSClient .EXPECT ().List (gomock .Any (), provider .azureManager .config .ResourceGroup ).Return (expectedScaleSets , nil )
103+ provider .azureManager .azClient .virtualMachineScaleSetsClient = mockVMSSClient
104+ mockVMSSVMClient := mockvmssvmclient .NewMockInterface (ctrl )
105+ mockVMSSVMClient .EXPECT ().List (gomock .Any (), provider .azureManager .config .ResourceGroup , "test-asg" , gomock .Any ()).Return (expectedVMSSVMs , nil ).AnyTimes ()
106+ provider .azureManager .azClient .virtualMachineScaleSetVMsClient = mockVMSSVMClient
107+
132108 registered := provider .azureManager .RegisterAsg (
133109 newTestScaleSet (provider .azureManager , "test-asg" ))
134110 assert .True (t , registered )
0 commit comments