@@ -22,19 +22,22 @@ import (
22
22
"bytes"
23
23
"context"
24
24
"encoding/json"
25
+ "fmt"
25
26
"io/ioutil"
26
27
"net/http"
27
28
"testing"
28
29
29
30
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
30
31
"github.com/Azure/go-autorest/autorest"
32
+ "github.com/Azure/go-autorest/autorest/azure"
31
33
"github.com/Azure/go-autorest/autorest/to"
32
34
"github.com/golang/mock/gomock"
33
35
"github.com/stretchr/testify/assert"
34
36
35
37
azclients "k8s.io/legacy-cloud-providers/azure/clients"
36
38
"k8s.io/legacy-cloud-providers/azure/clients/armclient"
37
39
"k8s.io/legacy-cloud-providers/azure/clients/armclient/mockarmclient"
40
+ "k8s.io/legacy-cloud-providers/azure/retry"
38
41
)
39
42
40
43
func TestGetNotFound (t * testing.T ) {
@@ -119,6 +122,41 @@ func TestCreateOrUpdate(t *testing.T) {
119
122
assert .Nil (t , rerr )
120
123
}
121
124
125
+ func TestCreateOrUpdateAsync (t * testing.T ) {
126
+ ctrl := gomock .NewController (t )
127
+ defer ctrl .Finish ()
128
+
129
+ vmss := getTestVMSS ("vmss1" )
130
+ armClient := mockarmclient .NewMockInterface (ctrl )
131
+ future := & azure.Future {}
132
+
133
+ armClient .EXPECT ().PutResourceAsync (gomock .Any (), to .String (vmss .ID ), vmss ).Return (future , nil ).Times (1 )
134
+ vmssClient := getTestVMSSClient (armClient )
135
+ _ , rerr := vmssClient .CreateOrUpdateAsync (context .TODO (), "rg" , "vmss1" , vmss )
136
+ assert .Nil (t , rerr )
137
+
138
+ retryErr := & retry.Error {RawError : fmt .Errorf ("error" )}
139
+ armClient .EXPECT ().PutResourceAsync (gomock .Any (), to .String (vmss .ID ), vmss ).Return (future , retryErr ).Times (1 )
140
+ _ , rerr = vmssClient .CreateOrUpdateAsync (context .TODO (), "rg" , "vmss1" , vmss )
141
+ assert .Equal (t , retryErr , rerr )
142
+ }
143
+
144
+ func TestWaitForAsyncOperationResult (t * testing.T ) {
145
+ ctrl := gomock .NewController (t )
146
+ defer ctrl .Finish ()
147
+
148
+ armClient := mockarmclient .NewMockInterface (ctrl )
149
+ response := & http.Response {
150
+ StatusCode : http .StatusOK ,
151
+ Body : ioutil .NopCloser (bytes .NewReader ([]byte ("" ))),
152
+ }
153
+
154
+ armClient .EXPECT ().WaitForAsyncOperationResult (gomock .Any (), & azure.Future {}, "VMSSWaitForAsyncOperationResult" ).Return (response , nil )
155
+ vmssClient := getTestVMSSClient (armClient )
156
+ _ , err := vmssClient .WaitForAsyncOperationResult (context .TODO (), & azure.Future {})
157
+ assert .Nil (t , err )
158
+ }
159
+
122
160
func TestDeleteInstances (t * testing.T ) {
123
161
ctrl := gomock .NewController (t )
124
162
defer ctrl .Finish ()
0 commit comments