@@ -19,6 +19,7 @@ limitations under the License.
19
19
package azure
20
20
21
21
import (
22
+ "fmt"
22
23
"testing"
23
24
24
25
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
@@ -32,11 +33,7 @@ func TestCreateFileShare(t *testing.T) {
32
33
ctrl := gomock .NewController (t )
33
34
defer ctrl .Finish ()
34
35
35
- cloud := & Cloud {}
36
- mockFileClient := mockfileclient .NewMockInterface (ctrl )
37
- mockFileClient .EXPECT ().CreateFileShare (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil ).AnyTimes ()
38
- cloud .FileClient = mockFileClient
39
-
36
+ cloud := & Cloud {controllerCommon : & controllerCommon {resourceGroup : "rg" }}
40
37
name := "baz"
41
38
sku := "sku"
42
39
kind := "StorageV2"
@@ -45,6 +42,7 @@ func TestCreateFileShare(t *testing.T) {
45
42
bogus := "bogus"
46
43
47
44
tests := []struct {
45
+ rg string
48
46
name string
49
47
acct string
50
48
acctType string
@@ -95,6 +93,25 @@ func TestCreateFileShare(t *testing.T) {
95
93
expectAcct : "baz" ,
96
94
expectKey : "key" ,
97
95
},
96
+ {
97
+ rg : "rg" ,
98
+ name : "foo" ,
99
+ acct : "" ,
100
+ acctType : sku ,
101
+ acctKind : kind ,
102
+ loc : location ,
103
+ gb : 10 ,
104
+ accounts : []storage.Account {
105
+ {Name : & name , Sku : & storage.Sku {Name : storage .SkuName (sku )}, Kind : storage .Kind (kind ), Location : & location },
106
+ },
107
+ keys : storage.AccountListKeysResult {
108
+ Keys : & []storage.AccountKey {
109
+ {Value : & value },
110
+ },
111
+ },
112
+ err : fmt .Errorf ("create fileshare error" ),
113
+ expectErr : true ,
114
+ },
98
115
{
99
116
name : "foo" ,
100
117
acct : "" ,
@@ -122,13 +139,17 @@ func TestCreateFileShare(t *testing.T) {
122
139
}
123
140
124
141
for _ , test := range tests {
142
+ mockFileClient := mockfileclient .NewMockInterface (ctrl )
143
+ cloud .FileClient = mockFileClient
144
+ mockFileClient .EXPECT ().CreateFileShare (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (test .err ).AnyTimes ()
145
+
125
146
mockStorageAccountsClient := mockstorageaccountclient .NewMockInterface (ctrl )
126
147
cloud .StorageAccountClient = mockStorageAccountsClient
127
148
mockStorageAccountsClient .EXPECT ().ListKeys (gomock .Any (), "rg" , gomock .Any ()).Return (test .keys , nil ).AnyTimes ()
128
149
mockStorageAccountsClient .EXPECT ().ListByResourceGroup (gomock .Any (), "rg" ).Return (test .accounts , nil ).AnyTimes ()
129
150
mockStorageAccountsClient .EXPECT ().Create (gomock .Any (), "rg" , gomock .Any (), gomock .Any ()).Return (nil ).AnyTimes ()
130
151
131
- account , key , err := cloud .CreateFileShare (test .name , test .acct , test .acctType , test .acctKind , "rg" , test .loc , test .gb )
152
+ account , key , err := cloud .CreateFileShare (test .name , test .acct , test .acctType , test .acctKind , test . rg , test .loc , test .gb )
132
153
if test .expectErr && err == nil {
133
154
t .Errorf ("unexpected non-error" )
134
155
continue
@@ -151,15 +172,12 @@ func TestDeleteFileShare(t *testing.T) {
151
172
defer ctrl .Finish ()
152
173
153
174
cloud := & Cloud {}
154
- mockFileClient := mockfileclient .NewMockInterface (ctrl )
155
- mockFileClient .EXPECT ().DeleteFileShare (gomock .Any (), gomock .Any (), gomock .Any ()).Return (nil ).AnyTimes ()
156
- cloud .FileClient = mockFileClient
157
-
158
175
tests := []struct {
159
176
rg string
160
177
acct string
161
178
name string
162
179
180
+ err error
163
181
expectErr bool
164
182
}{
165
183
{
@@ -169,11 +187,20 @@ func TestDeleteFileShare(t *testing.T) {
169
187
170
188
expectErr : false ,
171
189
},
190
+ {
191
+ rg : "rg" ,
192
+ acct : "bar" ,
193
+ name : "" ,
194
+
195
+ err : fmt .Errorf ("delete fileshare error" ),
196
+ expectErr : true ,
197
+ },
172
198
}
173
199
174
200
for _ , test := range tests {
175
- mockStorageAccountsClient := mockstorageaccountclient .NewMockInterface (ctrl )
176
- cloud .StorageAccountClient = mockStorageAccountsClient
201
+ mockFileClient := mockfileclient .NewMockInterface (ctrl )
202
+ cloud .FileClient = mockFileClient
203
+ mockFileClient .EXPECT ().DeleteFileShare (gomock .Any (), gomock .Any (), gomock .Any ()).Return (test .err ).Times (1 )
177
204
178
205
err := cloud .DeleteFileShare (test .rg , test .acct , test .name )
179
206
if test .expectErr && err == nil {
@@ -229,3 +256,44 @@ func TestResizeFileShare(t *testing.T) {
229
256
}
230
257
}
231
258
}
259
+
260
+ func TestGetFileShare (t * testing.T ) {
261
+ ctrl := gomock .NewController (t )
262
+ defer ctrl .Finish ()
263
+
264
+ cloud := & Cloud {}
265
+ mockFileClient := mockfileclient .NewMockInterface (ctrl )
266
+ mockFileClient .EXPECT ().GetFileShare (gomock .Any (), gomock .Any (), gomock .Any ()).Return (storage.FileShare {}, nil ).AnyTimes ()
267
+ cloud .FileClient = mockFileClient
268
+
269
+ tests := []struct {
270
+ rg string
271
+ acct string
272
+ name string
273
+
274
+ expectErr bool
275
+ }{
276
+ {
277
+ rg : "rg" ,
278
+ acct : "bar" ,
279
+ name : "foo" ,
280
+
281
+ expectErr : false ,
282
+ },
283
+ }
284
+
285
+ for _ , test := range tests {
286
+ mockStorageAccountsClient := mockstorageaccountclient .NewMockInterface (ctrl )
287
+ cloud .StorageAccountClient = mockStorageAccountsClient
288
+
289
+ _ , err := cloud .GetFileShare (test .rg , test .acct , test .name )
290
+ if test .expectErr && err == nil {
291
+ t .Errorf ("unexpected non-error" )
292
+ continue
293
+ }
294
+ if ! test .expectErr && err != nil {
295
+ t .Errorf ("unexpected error: %v" , err )
296
+ continue
297
+ }
298
+ }
299
+ }
0 commit comments