@@ -394,6 +394,62 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
394
394
ExpectErrorCode (rsp , err , codes .InvalidArgument )
395
395
})
396
396
397
+ It ("should fail with negative capacity" , func () {
398
+
399
+ By ("creating a volume" )
400
+ name := UniqueString ("sanity-controller-create-single-with-negative-capacity" )
401
+
402
+ vol , err := r .CreateVolume (
403
+ context .Background (),
404
+ & csi.CreateVolumeRequest {
405
+ Name : name ,
406
+ VolumeCapabilities : []* csi.VolumeCapability {
407
+ TestVolumeCapabilityWithAccessType (sc , csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ),
408
+ },
409
+ CapacityRange : & csi.CapacityRange {
410
+ RequiredBytes : - 1 * TestVolumeSize (sc ),
411
+ },
412
+ Secrets : sc .Secrets .CreateVolumeSecret ,
413
+ Parameters : sc .Config .TestVolumeParameters ,
414
+ },
415
+ )
416
+ Expect (err ).To (HaveOccurred ())
417
+ Expect (vol ).To (BeNil ())
418
+
419
+ serverError , ok := status .FromError (err )
420
+ Expect (ok ).To (BeTrue ())
421
+ Expect (serverError .Code () == codes .OutOfRange || serverError .Code () == codes .InvalidArgument , "unexpected error: %s" , serverError .Message ())
422
+ })
423
+
424
+ It ("should fail with invalid capacity" , func () {
425
+
426
+ By ("creating a volume" )
427
+ name := UniqueString ("sanity-controller-create-single-with-invalid-capacity" )
428
+
429
+ vol , err := r .CreateVolume (
430
+ context .Background (),
431
+ & csi.CreateVolumeRequest {
432
+ Name : name ,
433
+ VolumeCapabilities : []* csi.VolumeCapability {
434
+ TestVolumeCapabilityWithAccessType (sc , csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ),
435
+ },
436
+ CapacityRange : & csi.CapacityRange {
437
+ // LimitBytes < RequiredBytes is impossible to honor
438
+ RequiredBytes : TestVolumeExpandSize (sc ),
439
+ LimitBytes : TestVolumeSize (sc ),
440
+ },
441
+ Secrets : sc .Secrets .CreateVolumeSecret ,
442
+ Parameters : sc .Config .TestVolumeParameters ,
443
+ },
444
+ )
445
+ Expect (err ).To (HaveOccurred ())
446
+ Expect (vol ).To (BeNil ())
447
+
448
+ serverError , ok := status .FromError (err )
449
+ Expect (ok ).To (BeTrue ())
450
+ Expect (serverError .Code () == codes .OutOfRange || serverError .Code () == codes .InvalidArgument , "unexpected error: %s" , serverError .Message ())
451
+ })
452
+
397
453
// whether CreateVolume request with no capacity should fail or not depends on driver implementation
398
454
It ("should return appropriate values SingleNodeWriter NoCapacity" , func () {
399
455
0 commit comments