@@ -17,7 +17,6 @@ package util
1717import (
1818 "fmt"
1919 "reflect"
20- "strconv"
2120 "testing"
2221
2322 "github.com/opensds/opensds/pkg/utils"
@@ -375,6 +374,47 @@ func TestCreateFileShareSnapshotDBEntry(t *testing.T) {
375374 assertTestResult (t , result , expected )
376375 })
377376
377+ t .Run ("invalid fileshare snapshot description because it has some special characters" , func (t * testing.T ) {
378+ req .Name = "testsnap"
379+ req .Description = "#Snap !$!test"
380+ mockClient := new (dbtest.Client )
381+ mockClient .On ("GetFileShare" , context .NewAdminContext (), "bd5b12a8-a101-11e7-941e-d77981b584d8" ).Return (fileshare , nil )
382+ mockClient .On ("ListFileShareSnapshots" , context .NewAdminContext ()).Return (nil , nil )
383+ mockClient .On ("CreateFileShareSnapshot" , context .NewAdminContext (), req ).Return (& SampleShareSnapshots [0 ], nil )
384+ db .C = mockClient
385+
386+ _ , err := CreateFileShareSnapshotDBEntry (context .NewAdminContext (), req )
387+ expectedError := fmt .Sprintf ("invalid fileshare snapshot description because it has some special characters" )
388+ assertTestResult (t , err .Error (), expectedError )
389+ })
390+
391+ t .Run ("invalid fileshare snapshot name because it has some special characters" , func (t * testing.T ) {
392+ req .Name = "#Snap !$!test"
393+ req .Description = "test snapshot"
394+ mockClient := new (dbtest.Client )
395+ mockClient .On ("GetFileShare" , context .NewAdminContext (), "bd5b12a8-a101-11e7-941e-d77981b584d8" ).Return (fileshare , nil )
396+ mockClient .On ("ListFileShareSnapshots" , context .NewAdminContext ()).Return (nil , nil )
397+ mockClient .On ("CreateFileShareSnapshot" , context .NewAdminContext (), req ).Return (& SampleShareSnapshots [0 ], nil )
398+ db .C = mockClient
399+
400+ _ , err := CreateFileShareSnapshotDBEntry (context .NewAdminContext (), req )
401+ expectedError := fmt .Sprintf ("invalid fileshare snapshot name because it has some special characters" )
402+ assertTestResult (t , err .Error (), expectedError )
403+ })
404+
405+ t .Run ("names starting 'snapshot' are reserved" , func (t * testing.T ) {
406+ req .Name = "snapshotknow"
407+ req .Description = "test snapshot"
408+ mockClient := new (dbtest.Client )
409+ mockClient .On ("GetFileShare" , context .NewAdminContext (), "bd5b12a8-a101-11e7-941e-d77981b584d8" ).Return (fileshare , nil )
410+ mockClient .On ("ListFileShareSnapshots" , context .NewAdminContext ()).Return (nil , nil )
411+ mockClient .On ("CreateFileShareSnapshot" , context .NewAdminContext (), req ).Return (& SampleShareSnapshots [0 ], nil )
412+ db .C = mockClient
413+
414+ _ , err := CreateFileShareSnapshotDBEntry (context .NewAdminContext (), req )
415+ expectedError := fmt .Sprintf ("names starting 'snapshot' are reserved. Please choose a different snapshot name." )
416+ assertTestResult (t , err .Error (), expectedError )
417+ })
378418}
379419
380420func TestCreateFileShareDBEntry (t * testing.T ) {
@@ -422,44 +462,6 @@ func TestCreateFileShareDBEntry(t *testing.T) {
422462 assertTestResult (t , err .Error (), expectedError )
423463 })
424464
425- t .Run ("Empty file share name is allowed" , func (t * testing.T ) {
426- in .Size , in .Name , in .ProfileId = int64 (1 ), "" , "b3585ebe-c42c-120g-b28e-f373746a71ca"
427- mockClient := new (dbtest.Client )
428- mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
429- db .C = mockClient
430-
431- _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
432- expectedError := "empty fileshare name is not allowed. Please give valid name."
433- assertTestResult (t , err .Error (), expectedError )
434- })
435-
436- t .Run ("File share name length equal to 0 character are not allowed" , func (t * testing.T ) {
437- in .Name = utils .RandSeqWithAlnum (0 )
438- in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
439- mockClient := new (dbtest.Client )
440- mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
441- db .C = mockClient
442-
443- _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
444- expectedError := "empty fileshare name is not allowed. Please give valid name."
445- assertTestResult (t , err .Error (), expectedError )
446- })
447-
448- t .Run ("File share name length equal to 1 character are allowed" , func (t * testing.T ) {
449- in .Name = utils .RandSeqWithAlnum (1 )
450- in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
451- mockClient := new (dbtest.Client )
452- mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
453- db .C = mockClient
454-
455- var expected = & SampleFileShares [0 ]
456- result , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
457- if err != nil {
458- t .Errorf ("failed to create fileshare err is %v\n " , err )
459- }
460- assertTestResult (t , result , expected )
461- })
462-
463465 t .Run ("File share name length equal to 10 characters are allowed" , func (t * testing.T ) {
464466 in .Name = utils .RandSeqWithAlnum (10 )
465467 in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
@@ -504,30 +506,6 @@ func TestCreateFileShareDBEntry(t *testing.T) {
504506 }
505507 assertTestResult (t , result , expected )
506508 })
507-
508- t .Run ("File share name length more than 255 characters are not allowed" , func (t * testing.T ) {
509- in .Name = utils .RandSeqWithAlnum (256 )
510- in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
511- mockClient := new (dbtest.Client )
512- mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
513- db .C = mockClient
514-
515- _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
516- expectedError := "fileshare name length should not be more than 255 characters. input name length is : " + strconv .Itoa (len (in .Name ))
517- assertTestResult (t , err .Error (), expectedError )
518- })
519-
520- t .Run ("File share name length more than 255 characters are not allowed" , func (t * testing.T ) {
521- in .Name = utils .RandSeqWithAlnum (257 )
522- in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
523- mockClient := new (dbtest.Client )
524- mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
525- db .C = mockClient
526-
527- _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
528- expectedError := "fileshare name length should not be more than 255 characters. input name length is : " + strconv .Itoa (len (in .Name ))
529- assertTestResult (t , err .Error (), expectedError )
530- })
531509}
532510
533511func TestDeleteFileShareDBEntry (t * testing.T ) {
0 commit comments