-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvolume_test.go
481 lines (404 loc) · 20.6 KB
/
volume_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
/*
Copyright © 2019-2025 Dell Inc. or its subsidiaries. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package gounity
import (
"context"
"errors"
"fmt"
"testing"
"github.com/dell/gounity/mocks"
"github.com/dell/gounity/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
var (
volName = "unit-test-vol"
cloneVolumeName = "unit-test-clone-vol"
volID = "unity-volume-id"
cloneVolumeID string
hostIOLimitID string
anyArgs = []interface{}{mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything}
)
func TestFindHostIOLimitByName(t *testing.T) {
fmt.Println("Begin - Find Host IO Limit by Name Test")
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
ctx := context.Background()
// Mock the client.DoWithHeaders to return nil
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Once()
// Call the FindHostIOLimitByName function
hostIOLimit, err := testConf.volumeAPI.FindHostIOLimitByName(ctx, testConf.hostIOLimitName)
fmt.Println("hostIOLimit:", prettyPrintJSON(hostIOLimit), "Error:", err)
assert.NotNil(t, hostIOLimit.IoLimitPolicyContent)
// Negative cases
// Mock the client.DoWithHeaders to return an error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(fmt.Errorf("not found")).Once()
// Call the FindHostIOLimitByName function with a dummy name
_, err = testConf.volumeAPI.FindHostIOLimitByName(ctx, "dummy_hostio_1")
if err == nil {
t.Fatalf("Find Host IO Limit negative case failed: %v", err)
}
// Call the FindHostIOLimitByName function with an empty name
_, err = testConf.volumeAPI.FindHostIOLimitByName(ctx, "")
if err == nil {
t.Fatalf("Find Host IO Limit with empty name case failed: %v", err)
}
fmt.Println("Find Host IO Limit by Name Test - Successful")
}
func TestCreateLun(t *testing.T) {
fmt.Println("Begin - Create LUN Test")
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
ctx := context.Background()
// Mock FindStoragePoolByID to return nil
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Once()
// Mock isFeatureLicensed to return expected response
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.AnythingOfType("*types.LicenseInfo")).Return(nil).
Run(func(args mock.Arguments) {
resp := args.Get(5).(*types.LicenseInfo)
*resp = types.LicenseInfo{LicenseInfoContent: types.LicenseInfoContent{IsInstalled: true, IsValid: true}}
}).Twice()
// Mock create request to return nil
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Once()
_, err := testConf.volumeAPI.CreateLun(ctx, volName, testConf.poolID, "Description", 2368709120, 0, hostIOLimitID, true, false)
if err != nil {
t.Fatalf("Create LUN failed: %v", err)
}
// Negative cases
volNameTemp := ""
_, err = testConf.volumeAPI.CreateLun(ctx, volNameTemp, testConf.poolID, "Description", 2368709120, 0, hostIOLimitID, true, false)
if err == nil {
t.Fatalf("Create LUN with empty name case failed: %v", err)
}
volNameTemp = "vol-name-max-length-12345678901234567890123456789012345678901234567890"
_, err = testConf.volumeAPI.CreateLun(ctx, volNameTemp, testConf.poolID, "Description", 2368709120, 0, hostIOLimitID, true, false)
if err == nil {
t.Fatalf("Create LUN exceeding max name length case failed: %v", err)
}
// Mock FindStoragePoolByID to return error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(fmt.Errorf("storage pool not found")).Once()
poolIDTemp := "dummy_pool_1"
_, err = testConf.volumeAPI.CreateLun(ctx, volName, poolIDTemp, "Description", 2368709120, 0, hostIOLimitID, true, false)
if err == nil {
t.Fatalf("Create LUN with invalid pool name case failed: %v", err)
}
// Mock FindStoragePoolByID to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Once()
// Mock isFeatureLicensed to return expected response
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.AnythingOfType("*types.LicenseInfo")).Return(nil).
Run(func(args mock.Arguments) {
resp := args.Get(5).(*types.LicenseInfo)
*resp = types.LicenseInfo{LicenseInfoContent: types.LicenseInfoContent{IsInstalled: true, IsValid: true}}
}).Twice()
// Mock create volume to return error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(fmt.Errorf("volume already exists")).Once()
_, err = testConf.volumeAPI.CreateLun(ctx, volName, testConf.poolID, "Description", 2368709120, 0, hostIOLimitID, true, false)
if err == nil {
t.Fatalf("Create LUN with same name case failed: %v", err)
}
fmt.Println("Create LUN Test - Successful")
}
func TestFindVolumeByName(t *testing.T) {
fmt.Println("Begin - Find Volume By Name Test")
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
ctx := context.Background()
// Mock FindVolumeByName to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Once()
vol, err := testConf.volumeAPI.FindVolumeByName(ctx, volName)
fmt.Println("Find volume by Name:", prettyPrintJSON(vol), err)
if err != nil {
t.Fatalf("Find volume by Name failed: %v", err)
}
assert.NotNil(t, vol.VolumeContent.ResourceID)
// Negative cases
volNameTemp := ""
_, err = testConf.volumeAPI.FindVolumeByName(ctx, volNameTemp)
if err == nil {
t.Fatalf("Find volume by Name with empty name case failed: %v", err)
}
// Mock FindVolumeByName to return error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(fmt.Errorf("volume not found")).Once()
volNameTemp = "dummy_volume_1"
_, err = testConf.volumeAPI.FindVolumeByName(ctx, volNameTemp)
if err == nil {
t.Fatalf("Find volume by Name with invalid name case failed: %v", err)
}
fmt.Println("Find Volume by Name Test - Successful")
}
func TestFindVolumeByID(t *testing.T) {
fmt.Println("Begin - Find Volume By Name Test")
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
ctx := context.Background()
// Mock FindVolumeByID to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Once()
vol, err := testConf.volumeAPI.FindVolumeByID(ctx, volID)
fmt.Println("Find volume by Name:", prettyPrintJSON(vol), err)
if err != nil {
t.Fatalf("Find volume by Id failed: %v", err)
}
// Negative cases
volIDTemp := ""
_, err = testConf.volumeAPI.FindVolumeByID(ctx, volIDTemp)
if err == nil {
t.Fatalf("Find volume by Id with empty Id case failed: %v", err)
}
// Mock FindVolumeByID to return error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(fmt.Errorf("volume not found")).Once()
volIDTemp = "dummy_vol_sv_1"
_, err = testConf.volumeAPI.FindVolumeByID(ctx, volIDTemp)
if err == nil {
t.Fatalf("Find volume by Id with invalid Id case failed: %v", err)
}
fmt.Println("Find Volume by Id Test - Successful")
}
func TestListVolumes(t *testing.T) {
fmt.Println("Begin - List Volumes Test")
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
ctx := context.Background()
// Mock ListVolumes to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Run(func(args mock.Arguments) {
resp := args.Get(5).(*types.ListVolumes)
resp.Volumes = make([]types.Volume, 10)
}).Once()
vols, _, err := testConf.volumeAPI.ListVolumes(ctx, 11, 10)
fmt.Println("List volumes count: ", len(vols))
if len(vols) <= 10 {
fmt.Println("List volume success")
} else {
t.Fatalf("List volumes failed: %v", err)
}
fmt.Println("List Volume Test - Successful")
}
func TestExportVolume(t *testing.T) {
fmt.Println("Begin - Export Volume Test")
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
ctx := context.Background()
// Mock FindHostByName to return a valid host object
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
testConf.volumeAPI.client.api.(*mocks.Client).On("FindHostByName", ctx, testConf.nodeHostName).Return(&types.Host{
HostContent: types.HostContent{
ID: "valid_host_id",
},
}, nil)
// Find the host
host, err := testConf.hostAPI.FindHostByName(ctx, testConf.nodeHostName)
if err != nil {
t.Fatalf("Find Host failed: %v", err)
}
// Mock ExportVolume to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
err = testConf.volumeAPI.ExportVolume(ctx, volID, host.HostContent.ID)
if err != nil {
t.Fatalf("ExportVolume failed: %v", err)
}
// Negative case for Delete Volume
// Mock executeWithRetryAuthenticate to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
// Mock FindVolumeByID to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
// Mock DeleteVolume to return a specific error type
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&types.Error{
ErrorContent: types.ErrorContent{
Message: []types.ErrorMessage{
{EnUS: "failed to delete exported volume"},
},
HTTPStatusCode: 500,
ErrorCode: 1234,
},
}).Once()
err = testConf.volumeAPI.DeleteVolume(ctx, volID)
if err == nil {
t.Fatalf("Delete volume on exported volume case failed: %v", err)
}
fmt.Println("Export Volume Test - Successful")
}
func TestUnexportVolume(t *testing.T) {
fmt.Println("Begin - Unexport Volume Test")
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
ctx := context.Background()
// Mock UnexportVolume to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
err := testConf.volumeAPI.UnexportVolume(ctx, volID)
if err != nil {
t.Fatalf("UnexportVolume failed: %v", err)
}
fmt.Println("Unexport Volume Test - Successful")
}
func TestExpandVolumeTest(t *testing.T) {
fmt.Println("Begin - Expand Volume Test")
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
ctx := context.Background()
testConf.fileAPI.client.api.(*mocks.Client).On("FindVolumeByID", ctx, "volID").Return(&types.VolumeContent{SizeTotal: 5368709120}, nil).Once()
testConf.fileAPI.client.api.(*mocks.Client).On("FindVolumeByID", ctx, "dummy_vol_sv_1").Return(nil, errors.New("unable to find volume Id")).Once()
testConf.fileAPI.client.api.(*mocks.Client).On("executeWithRetryAuthenticate", ctx, "POST", "api/modify/lun/volID", mock.Anything, nil).Return(nil).Once()
testConf.fileAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Maybe()
err := testConf.volumeAPI.ExpandVolume(ctx, "volID", 5368709120)
if err != nil {
t.Fatalf("Expand volume failed: %v", err)
}
err = testConf.volumeAPI.ExpandVolume(ctx, volID, 5368709120)
if err != nil {
t.Fatalf("Expand volume with same size failed: %v", err)
}
// Negative cases
volIDTemp := "dummy_vol_sv_1"
err = testConf.volumeAPI.ExpandVolume(ctx, volIDTemp, 5368709120)
if err != nil {
t.Fatalf("Expand volume with invalid Id case failed: %v", err)
}
err = testConf.volumeAPI.ExpandVolume(ctx, volID, 4368709120)
if err != nil {
t.Fatalf("Expand volume with smaller size case failed: %v", err)
}
fmt.Println("Expand Volume Test - Successful")
}
func TestCreateCloneFromVolume(t *testing.T) {
fmt.Println("Begin - Create clone from Volume Test")
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
ctx := context.Background()
// Mock responses for CreateSnapshot, CreteLunThinClone
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Times(2)
_, err := testConf.volumeAPI.CreateCloneFromVolume(ctx, cloneVolumeName, volID)
assert.Nil(t, err)
// Negative Test Case: Create Snapshot Failed
_, err = testConf.volumeAPI.CreateCloneFromVolume(ctx, cloneVolumeName, "")
assert.ErrorIs(t, err, ErrorCreateSnapshotFailed)
// Negative Test Case: Creating clone with same name
// Mock responses for CreateSnapshot
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
// Mock CreteLunThinCloneto return error volume with a same exists
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("volume with a same exists")).Once()
// Mock responses for DeleteSnapshot
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
_, err = testConf.volumeAPI.CreateCloneFromVolume(ctx, cloneVolumeName, volID)
assert.ErrorIs(t, err, ErrorCloningFailed)
fmt.Println("Create clone from Volume Test - Successful")
}
func TestModifyVolumeExportTest(t *testing.T) {
fmt.Println("Begin - Modify Volume Export Test")
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
ctx := context.Background()
// Clear existing expectations
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
// Mock the DoWithHeaders method to handle multiple calls
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Maybe()
// Mock the RenameVolume method to return an error for non-existent volume ID
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, "POST", "/api/instances/storageResource/dummy_vol_1/action/modifyLun", mock.Anything, mock.Anything).Return(fmt.Errorf("volume not found")).Once()
// Create a list of host IDs
hostIDList := []string{}
for _, hostName := range testConf.hostList {
host, err := testConf.hostAPI.FindHostByName(ctx, hostName)
if err != nil {
t.Fatalf("Find host by name %s failed. Error: %v", hostName, err)
}
hostIDList = append(hostIDList, host.HostContent.ID)
}
// Modify the volume export
if err := testConf.volumeAPI.ModifyVolumeExport(ctx, volID, hostIDList); err != nil {
t.Fatalf("Modify Volume Export failed: %v", err)
}
// Rename the volume
volName += "_renamed"
if err := testConf.volumeAPI.RenameVolume(ctx, volName, volID); err != nil {
t.Fatalf("Rename existing volume failed. Error: %v", err)
}
// Negative test case: Attempt to rename a non-existent volume
volIDTemp := "dummy_vol_1"
if err := testConf.volumeAPI.RenameVolume(ctx, volName, volIDTemp); err != nil {
t.Fatalf("Expected error when renaming non-existent volume, got none")
}
// Unexport the volume from the host
if err := testConf.volumeAPI.UnexportVolume(ctx, volID); err != nil {
t.Fatalf("Unexport volume failed. Error: %v", err)
}
fmt.Println("Modify Volume Export Test Successful")
}
func TestDeleteVolumeTest(t *testing.T) {
fmt.Println("Begin - Delete Volume Test")
ctx := context.Background()
// Clear existing expectations
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
err := testConf.volumeAPI.DeleteVolume(ctx, "")
assert.ErrorContains(t, err, "Volume Id cannot be empty")
// Mock the executeWithRetryAuthenticate, FindVolumeByID, executeWithRetryAuthenticate method to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Times(3)
err = testConf.volumeAPI.DeleteVolume(ctx, volID)
assert.Nil(t, err)
// Mock the executeWithRetryAuthenticate method to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Once()
// Mock the FindVolumeByID method to return voume not found error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(fmt.Errorf("volume not found")).Once()
err = testConf.volumeAPI.DeleteVolume(ctx, volID)
assert.Errorf(t, err, "volume not found")
// Mock the executeWithRetryAuthenticate method to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Twice()
// Mock the FindVolumeByID method to return voume not found error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(errors.New(DependentClonesErrorCode)).Once()
// Mock the RenameVolume method to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Once()
err = testConf.volumeAPI.DeleteVolume(ctx, volID)
assert.Nil(t, err)
// Mock the executeWithRetryAuthenticate method to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Once()
// Mock the FindVolumeByID method to return expected response
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).
Run(func(args mock.Arguments) {
resp := args.Get(5).(*types.Volume)
*resp = types.Volume{
VolumeContent: types.VolumeContent{
IsThinClone: true,
ParentVolume: types.StorageResource{ID: volID},
},
}
}).Once()
// Mock the executeWithRetryAuthenticate method to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Once()
// Mock the sourceVolID FindVolumeByID method to return expected response
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).
Run(func(args mock.Arguments) {
resp := args.Get(5).(*types.Volume)
*resp = types.Volume{
VolumeContent: types.VolumeContent{
Name: MarkVolumeForDeletion,
},
}
}).Once()
// Mock the deleteSourceVol executeWithRetryAuthenticate method to return no error
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", anyArgs...).Return(nil).Once()
err = testConf.volumeAPI.DeleteVolume(ctx, volID)
assert.Nil(t, err)
fmt.Println("Delete Volume Test - Successful")
}
func TestGetMaxVolumeSizeTest(t *testing.T) {
fmt.Println("Begin - Get Max Volume Size")
testConf.volumeAPI.client.api.(*mocks.Client).ExpectedCalls = nil
ctx := context.Background()
// Mock the DoWithHeaders method to handle multiple calls
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Maybe()
// Mock the GetMaxVolumeSize method to return an error for invalid systemLimitID
testConf.volumeAPI.client.api.(*mocks.Client).On("DoWithHeaders", mock.Anything, "GET", "/api/types/systemLimit/instances/dummy_name", mock.Anything, mock.Anything).Return(fmt.Errorf("invalid systemLimitID")).Once()
// Positive case: Get maximum volume size with a valid system limit ID
systemLimitID := "Limit_MaxLUNSize"
if _, err := testConf.volumeAPI.GetMaxVolumeSize(ctx, systemLimitID); err != nil {
t.Fatalf("Get maximum volume size failed: %v", err)
}
// Negative case: Attempt to get maximum volume size with an empty system limit ID
systemLimitID = ""
if _, err := testConf.volumeAPI.GetMaxVolumeSize(ctx, systemLimitID); err == nil {
t.Fatalf("Expected error when getting maximum volume size with empty systemLimitID, got none")
}
// Negative case: Attempt to get maximum volume size with an invalid system limit ID
systemLimitID = "dummy_name"
if _, err := testConf.volumeAPI.GetMaxVolumeSize(ctx, systemLimitID); err != nil {
t.Fatalf("Expected error when getting maximum volume size with invalid systemLimitID, got none")
}
fmt.Println("Get Max Volume Size - Successful")
}