@@ -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,19 @@ func TestCreateFileShareSnapshotDBEntry(t *testing.T) {
375374 assertTestResult (t , result , expected )
376375 })
377376
377+ t .Run ("names starting 'snapshot' are reserved" , func (t * testing.T ) {
378+ req .Name = "snapshotknow"
379+ req .Description = "test snapshot"
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 ("names starting 'snapshot' are reserved. Please choose a different snapshot name." )
388+ assertTestResult (t , err .Error (), expectedError )
389+ })
378390}
379391
380392func TestCreateFileShareDBEntry (t * testing.T ) {
@@ -422,44 +434,6 @@ func TestCreateFileShareDBEntry(t *testing.T) {
422434 assertTestResult (t , err .Error (), expectedError )
423435 })
424436
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-
463437 t .Run ("File share name length equal to 10 characters are allowed" , func (t * testing.T ) {
464438 in .Name = utils .RandSeqWithAlnum (10 )
465439 in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
@@ -504,30 +478,6 @@ func TestCreateFileShareDBEntry(t *testing.T) {
504478 }
505479 assertTestResult (t , result , expected )
506480 })
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- })
531481}
532482
533483func TestDeleteFileShareDBEntry (t * testing.T ) {
0 commit comments