@@ -43,6 +43,36 @@ func TestReconcileNetworkInterface(t *testing.T) {
4343 expectedError string
4444 expect func (s * mock_networkinterfaces.MockNICScopeMockRecorder , m * mock_networkinterfaces.MockClientMockRecorder )
4545 }{
46+ {
47+ name : "network interface already exists" ,
48+ expectedError : "" ,
49+ expect : func (s * mock_networkinterfaces.MockNICScopeMockRecorder , m * mock_networkinterfaces.MockClientMockRecorder ) {
50+ s .NICSpecs ().Return ([]azure.NICSpec {
51+ {
52+ Name : "nic-1" ,
53+ MachineName : "azure-test1" ,
54+ SubnetName : "my-subnet" ,
55+ VNetName : "my-vnet" ,
56+ VNetResourceGroup : "my-rg" ,
57+ VMSize : "Standard_D2v2" ,
58+ },
59+ {
60+ Name : "nic-2" ,
61+ MachineName : "azure-test1" ,
62+ SubnetName : "my-subnet" ,
63+ VNetName : "my-vnet" ,
64+ VNetResourceGroup : "my-rg" ,
65+ VMSize : "Standard_D2v2" ,
66+ },
67+ })
68+ s .SubscriptionID ().AnyTimes ().Return ("123" )
69+ s .ResourceGroup ().AnyTimes ().Return ("my-rg" )
70+ s .Location ().AnyTimes ().Return ("fake-location" )
71+ gomock .InOrder (
72+ m .Get (context .TODO (), "my-rg" , "nic-1" ),
73+ m .Get (context .TODO (), "my-rg" , "nic-2" ))
74+ },
75+ },
4676 {
4777 name : "node network interface create fails" ,
4878 expectedError : "failed to create network interface my-net-interface in resource group my-rg: #: Internal Server Error: StatusCode=500" ,
@@ -63,6 +93,8 @@ func TestReconcileNetworkInterface(t *testing.T) {
6393 s .ResourceGroup ().AnyTimes ().Return ("my-rg" )
6494 s .Location ().AnyTimes ().Return ("fake-location" )
6595 gomock .InOrder (
96+ m .Get (context .TODO (), "my-rg" , "my-net-interface" ).
97+ Return (network.Interface {}, autorest .NewErrorWithResponse ("" , "" , & http.Response {StatusCode : 404 }, "Not found" )),
6698 m .CreateOrUpdate (context .TODO (), "my-rg" , "my-net-interface" , gomock .AssignableToTypeOf (network.Interface {})).
6799 Return (autorest .NewErrorWithResponse ("" , "" , & http.Response {StatusCode : 500 }, "Internal Server Error" )))
68100 },
@@ -90,6 +122,8 @@ func TestReconcileNetworkInterface(t *testing.T) {
90122 s .ResourceGroup ().AnyTimes ().Return ("my-rg" )
91123 s .Location ().AnyTimes ().Return ("fake-location" )
92124 s .V (gomock .AssignableToTypeOf (2 )).AnyTimes ().Return (klogr .New ())
125+ m .Get (context .TODO (), "my-rg" , "my-net-interface" ).
126+ Return (network.Interface {}, autorest .NewErrorWithResponse ("" , "" , & http.Response {StatusCode : 404 }, "Not found" ))
93127 m .CreateOrUpdate (context .TODO (), "my-rg" , "my-net-interface" , gomockinternal .DiffEq (network.Interface {
94128 Location : to .StringPtr ("fake-location" ),
95129 InterfacePropertiesFormat : & network.InterfacePropertiesFormat {
@@ -131,6 +165,8 @@ func TestReconcileNetworkInterface(t *testing.T) {
131165 s .Location ().AnyTimes ().Return ("fake-location" )
132166 s .V (gomock .AssignableToTypeOf (3 )).AnyTimes ().Return (klogr .New ())
133167 gomock .InOrder (
168+ m .Get (context .TODO (), "my-rg" , "my-net-interface" ).
169+ Return (network.Interface {}, autorest .NewErrorWithResponse ("" , "" , & http.Response {StatusCode : 404 }, "Not found" )),
134170 m .CreateOrUpdate (context .TODO (), "my-rg" , "my-net-interface" , gomockinternal .DiffEq (network.Interface {
135171 Location : to .StringPtr ("fake-location" ),
136172 InterfacePropertiesFormat : & network.InterfacePropertiesFormat {
@@ -173,6 +209,8 @@ func TestReconcileNetworkInterface(t *testing.T) {
173209 s .ResourceGroup ().AnyTimes ().Return ("my-rg" )
174210 s .Location ().AnyTimes ().Return ("fake-location" )
175211 s .V (gomock .AssignableToTypeOf (3 )).AnyTimes ().Return (klogr .New ())
212+ m .Get (context .TODO (), "my-rg" , "my-net-interface" ).
213+ Return (network.Interface {}, autorest .NewErrorWithResponse ("" , "" , & http.Response {StatusCode : 404 }, "Not found" ))
176214 m .CreateOrUpdate (context .TODO (), "my-rg" , "my-net-interface" , gomockinternal .DiffEq (network.Interface {
177215 Location : to .StringPtr ("fake-location" ),
178216 InterfacePropertiesFormat : & network.InterfacePropertiesFormat {
@@ -214,6 +252,8 @@ func TestReconcileNetworkInterface(t *testing.T) {
214252 s .ResourceGroup ().AnyTimes ().Return ("my-rg" )
215253 s .Location ().AnyTimes ().Return ("fake-location" )
216254 s .V (gomock .AssignableToTypeOf (3 )).AnyTimes ().Return (klogr .New ())
255+ m .Get (context .TODO (), "my-rg" , "my-public-net-interface" ).
256+ Return (network.Interface {}, autorest .NewErrorWithResponse ("" , "" , & http.Response {StatusCode : 404 }, "Not found" ))
217257 m .CreateOrUpdate (context .TODO (), "my-rg" , "my-public-net-interface" , gomock .AssignableToTypeOf (network.Interface {}))
218258 },
219259 },
@@ -237,6 +277,8 @@ func TestReconcileNetworkInterface(t *testing.T) {
237277 s .ResourceGroup ().AnyTimes ().Return ("my-rg" )
238278 s .Location ().AnyTimes ().Return ("fake-location" )
239279 s .V (gomock .AssignableToTypeOf (2 )).AnyTimes ().Return (klogr .New ())
280+ m .Get (context .TODO (), "my-rg" , "my-net-interface" ).
281+ Return (network.Interface {}, autorest .NewErrorWithResponse ("" , "" , & http.Response {StatusCode : 404 }, "Not found" ))
240282 m .CreateOrUpdate (context .TODO (), "my-rg" , "my-net-interface" , gomockinternal .DiffEq (network.Interface {
241283 Location : to .StringPtr ("fake-location" ),
242284 InterfacePropertiesFormat : & network.InterfacePropertiesFormat {
@@ -277,6 +319,8 @@ func TestReconcileNetworkInterface(t *testing.T) {
277319 s .V (gomock .AssignableToTypeOf (2 )).AnyTimes ().Return (klogr .New ())
278320 s .Location ().AnyTimes ().Return ("fake-location" )
279321 s .V (gomock .AssignableToTypeOf (2 )).AnyTimes ().Return (klogr .New ())
322+ m .Get (context .TODO (), "my-rg" , "my-net-interface" ).
323+ Return (network.Interface {}, autorest .NewErrorWithResponse ("" , "" , & http.Response {StatusCode : 404 }, "Not found" ))
280324 m .CreateOrUpdate (context .TODO (), "my-rg" , "my-net-interface" , gomockinternal .DiffEq (network.Interface {
281325 Location : to .StringPtr ("fake-location" ),
282326 InterfacePropertiesFormat : & network.InterfacePropertiesFormat {
@@ -301,7 +345,7 @@ func TestReconcileNetworkInterface(t *testing.T) {
301345 tc := tc
302346 t .Run (tc .name , func (t * testing.T ) {
303347 g := NewWithT (t )
304- // t.Parallel()
348+ t .Parallel ()
305349 mockCtrl := gomock .NewController (t )
306350 defer mockCtrl .Finish ()
307351 scopeMock := mock_networkinterfaces .NewMockNICScope (mockCtrl )
0 commit comments