@@ -25,9 +25,9 @@ import (
2525 "strings"
2626 "testing"
2727
28- "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute"
28+ "github.com/Azure/azure-sdk-for-go/sdk/azcore"
29+ "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
2930 "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-02-01/network"
30- "github.com/Azure/go-autorest/autorest"
3131 "github.com/Azure/go-autorest/autorest/to"
3232 "github.com/ghodss/yaml"
3333 "github.com/golang/mock/gomock"
@@ -181,21 +181,22 @@ type FakeVMService struct {
181181// Get returns fake success.
182182func (s * FakeVMService ) Get (ctx context.Context , spec azure.Spec ) (interface {}, error ) {
183183 s .GetCallCount ++
184- return compute .VirtualMachine {
184+ vm := armcompute .VirtualMachine {
185185 ID : to .StringPtr (s .ID ),
186186 Name : to .StringPtr (s .Name ),
187- VirtualMachineProperties : & compute .VirtualMachineProperties {
187+ Properties : & armcompute .VirtualMachineProperties {
188188 ProvisioningState : to .StringPtr (s .ProvisioningState ),
189- NetworkProfile : & compute .NetworkProfile {
190- NetworkInterfaces : & []compute .NetworkInterfaceReference {
189+ NetworkProfile : & armcompute .NetworkProfile {
190+ NetworkInterfaces : [] * armcompute .NetworkInterfaceReference {
191191 {
192- ID : to .StringPtr ("machine-test-nic" ),
193- NetworkInterfaceReferenceProperties : & compute .NetworkInterfaceReferenceProperties {},
192+ ID : to .StringPtr ("machine-test-nic" ),
193+ Properties : & armcompute .NetworkInterfaceReferenceProperties {},
194194 },
195195 },
196196 },
197197 },
198- }, nil
198+ }
199+ return armcompute.VirtualMachinesClientGetResponse {VirtualMachine : vm }, nil
199200}
200201
201202// CreateOrUpdate returns fake success.
@@ -393,9 +394,10 @@ func (s *FakeVMCheckZonesService) Get(ctx context.Context, spec azure.Spec) (int
393394 return nil , errors .New ("vm not found" )
394395 }
395396
396- return & compute.VirtualMachine {
397- VirtualMachineProperties : & compute.VirtualMachineProperties {},
398- }, nil
397+ vm := armcompute.VirtualMachine {
398+ Properties : & armcompute.VirtualMachineProperties {},
399+ }
400+ return armcompute.VirtualMachinesClientGetResponse {VirtualMachine : vm }, nil
399401}
400402
401403// CreateOrUpdate returns fake success.
@@ -731,19 +733,20 @@ func TestMachineEvents(t *testing.T) {
731733 })
732734
733735 networkSvc .EXPECT ().CreateOrUpdate (gomock .Any (), gomock .Any ()).Return (nil ).AnyTimes ()
734- vmSvc . EXPECT (). Get ( gomock . Any (), gomock . Any ()). Return (compute .VirtualMachine {
736+ vm := armcompute .VirtualMachine {
735737 ID : ptr.To [string ]("vm-id" ),
736738 Name : ptr.To [string ]("vm-name" ),
737- VirtualMachineProperties : & compute .VirtualMachineProperties {
739+ Properties : & armcompute .VirtualMachineProperties {
738740 ProvisioningState : ptr.To [string ]("Succeeded" ),
739- HardwareProfile : & compute .HardwareProfile {
740- VMSize : compute . VirtualMachineSizeTypesStandardB2ms ,
741+ HardwareProfile : & armcompute .HardwareProfile {
742+ VMSize : ptr . To ( armcompute . VirtualMachineSizeTypesStandardB2Ms ) ,
741743 },
742- OsProfile : & compute .OSProfile {
744+ OSProfile : & armcompute .OSProfile {
743745 ComputerName : ptr.To [string ]("vm-name" ),
744746 },
745747 },
746- }, nil ).AnyTimes ()
748+ }
749+ vmSvc .EXPECT ().Get (gomock .Any (), gomock .Any ()).Return (armcompute.VirtualMachinesClientGetResponse {VirtualMachine : vm }, nil ).AnyTimes ()
747750 vmSvc .EXPECT ().Delete (gomock .Any (), gomock .Any ()).Return (nil ).AnyTimes ()
748751 disksSvc .EXPECT ().Delete (gomock .Any (), gomock .Any ()).Return (nil ).AnyTimes ()
749752 networkSvc .EXPECT ().Delete (gomock .Any (), gomock .Any ()).Return (nil ).AnyTimes ()
@@ -788,25 +791,21 @@ func TestStatusCodeBasedCreationErrors(t *testing.T) {
788791 cases := []struct {
789792 name string
790793 operation func (actuator * Actuator , machine * machinev1.Machine )
791- event string
792- statusCode interface {}
794+ statusCode int
793795 requeable bool
794796 }{
795797 {
796798 name : "InvalidConfig" ,
797- event : "Warning FailedCreate InvalidConfiguration: failed to reconcile machine \" azure-actuator-testing-machine\" : compute.VirtualMachinesClient#CreateOrUpdate: MOCK: StatusCode=400" ,
798799 statusCode : 400 ,
799800 requeable : false ,
800801 },
801802 {
802803 name : "CreateMachine" ,
803- event : "Warning FailedCreate CreateError: failed to reconcile machine \" azure-actuator-testing-machine\" s: failed to create vm azure-actuator-testing-machine: failed to create VM: failed to create or get machine: compute.VirtualMachinesClient#CreateOrUpdate: MOCK: StatusCode=300" ,
804804 statusCode : 300 ,
805805 requeable : true ,
806806 },
807807 {
808808 name : "CreateMachine" ,
809- event : "Warning FailedCreate CreateError: failed to reconcile machine \" azure-actuator-testing-machine\" s: failed to create vm azure-actuator-testing-machine: failed to create VM: failed to create or get machine: compute.VirtualMachinesClient#CreateOrUpdate: MOCK: StatusCode=401" ,
810809 statusCode : 401 ,
811810 requeable : true ,
812811 },
@@ -850,11 +849,13 @@ func TestStatusCodeBasedCreationErrors(t *testing.T) {
850849 })
851850
852851 networkSvc .EXPECT ().CreateOrUpdate (gomock .Any (), gomock .Any ()).Return (nil ).Times (1 )
853- azureErr := autorest .NewError ("compute.VirtualMachinesClient" , "CreateOrUpdate" , "MOCK" )
854- azureErr .StatusCode = tc .statusCode
852+ var azureErr error = & azcore.ResponseError {
853+ ErrorCode : fmt .Sprintf ("StatusCode=%d" , tc .statusCode ),
854+ StatusCode : tc .statusCode ,
855+ }
855856 wrapErr := fmt .Errorf ("failed to create or get machine: %w" , azureErr )
856857 vmSvc .EXPECT ().CreateOrUpdate (gomock .Any (), gomock .Any ()).Return (wrapErr ).Times (1 )
857- vmSvc .EXPECT ().Get (gomock .Any (), gomock .Any ()).Return (nil , autorest . NewError ( " compute.VirtualMachinesClient" , " Get" , "MOCK " )).Times (1 )
858+ vmSvc .EXPECT ().Get (gomock .Any (), gomock .Any ()).Return (nil , fmt . Errorf ( "mock compute.VirtualMachinesClient Get error " )).Times (1 )
858859 availabilityZonesSvc .EXPECT ().Get (gomock .Any (), gomock .Any ()).Return ([]string {"testzone" }, nil ).Times (1 )
859860
860861 _ , ok := machineActuator .Create (context .TODO (), machine ).(* machineapierrors.RequeueAfterError )
@@ -867,11 +868,11 @@ func TestStatusCodeBasedCreationErrors(t *testing.T) {
867868
868869 select {
869870 case event := <- eventsChannel :
870- if event != tc . event {
871- t .Errorf ("Expected %q event , got %q" , tc . event , event )
871+ if ! strings . Contains ( event , azureErr . Error ()) {
872+ t .Errorf ("Expected event to contain error %q , got %q" , azureErr . Error () , event )
872873 }
873874 default :
874- t .Errorf ("Expected %q event, got none" , tc . event )
875+ t .Errorf ("Expected an event containing error %q , got none" , azureErr . Error () )
875876 }
876877 })
877878 }
0 commit comments