@@ -380,7 +380,7 @@ func TestCreateFileShareSnapshotDBEntry(t *testing.T) {
380380func TestCreateFileShareDBEntry (t * testing.T ) {
381381 var in = & model.FileShareSpec {
382382 BaseModel : & model.BaseModel {},
383- Name : "sample-fileshare-01 " ,
383+ Name : "samplefileshare01 " ,
384384 Description : "This is a sample fileshare for testing" ,
385385 Size : int64 (1 ),
386386 ProfileId : "b3585ebe-c42c-120g-b28e-f373746a71ca" ,
@@ -390,6 +390,7 @@ func TestCreateFileShareDBEntry(t *testing.T) {
390390 t .Run ("Everything should work well" , func (t * testing.T ) {
391391 mockClient := new (dbtest.Client )
392392 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
393+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
393394 db .C = mockClient
394395
395396 var expected = & SampleFileShares [0 ]
@@ -404,6 +405,7 @@ func TestCreateFileShareDBEntry(t *testing.T) {
404405 in .Size = int64 (- 2 )
405406 mockClient := new (dbtest.Client )
406407 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
408+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
407409 db .C = mockClient
408410
409411 _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
@@ -415,6 +417,7 @@ func TestCreateFileShareDBEntry(t *testing.T) {
415417 in .ProfileId = ""
416418 mockClient := new (dbtest.Client )
417419 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
420+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
418421 db .C = mockClient
419422
420423 _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
@@ -426,6 +429,7 @@ func TestCreateFileShareDBEntry(t *testing.T) {
426429 in .Size , in .Name , in .ProfileId = int64 (1 ), "" , "b3585ebe-c42c-120g-b28e-f373746a71ca"
427430 mockClient := new (dbtest.Client )
428431 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
432+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
429433 db .C = mockClient
430434
431435 _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
@@ -438,6 +442,7 @@ func TestCreateFileShareDBEntry(t *testing.T) {
438442 in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
439443 mockClient := new (dbtest.Client )
440444 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
445+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
441446 db .C = mockClient
442447
443448 _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
@@ -450,6 +455,7 @@ func TestCreateFileShareDBEntry(t *testing.T) {
450455 in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
451456 mockClient := new (dbtest.Client )
452457 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
458+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
453459 db .C = mockClient
454460
455461 var expected = & SampleFileShares [0 ]
@@ -465,6 +471,7 @@ func TestCreateFileShareDBEntry(t *testing.T) {
465471 in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
466472 mockClient := new (dbtest.Client )
467473 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
474+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
468475 db .C = mockClient
469476
470477 var expected = & SampleFileShares [0 ]
@@ -480,6 +487,7 @@ func TestCreateFileShareDBEntry(t *testing.T) {
480487 in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
481488 mockClient := new (dbtest.Client )
482489 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
490+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
483491 db .C = mockClient
484492
485493 var expected = & SampleFileShares [0 ]
@@ -495,6 +503,7 @@ func TestCreateFileShareDBEntry(t *testing.T) {
495503 in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
496504 mockClient := new (dbtest.Client )
497505 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
506+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
498507 db .C = mockClient
499508
500509 var expected = & SampleFileShares [0 ]
@@ -510,6 +519,7 @@ func TestCreateFileShareDBEntry(t *testing.T) {
510519 in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
511520 mockClient := new (dbtest.Client )
512521 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
522+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
513523 db .C = mockClient
514524
515525 _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
@@ -522,23 +532,63 @@ func TestCreateFileShareDBEntry(t *testing.T) {
522532 in .Size , in .ProfileId = int64 (1 ), "b3585ebe-c42c-120g-b28e-f373746a71ca"
523533 mockClient := new (dbtest.Client )
524534 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
535+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
525536 db .C = mockClient
526537
527538 _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
528539 expectedError := "fileshare name length should not be more than 255 characters. input name length is : " + strconv .Itoa (len (in .Name ))
529540 assertTestResult (t , err .Error (), expectedError )
530541 })
531542
543+ t .Run ("Special characters in file share name are not allowed" , func (t * testing.T ) {
544+ in .Size , in .Name , in .ProfileId , in .Description = int64 (1 ), "#Share !$!test" , "b3585ebe-c42c-120g-b28e-f373746a71ca" , "File share test"
545+ mockClient := new (dbtest.Client )
546+ mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
547+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
548+ db .C = mockClient
549+
550+ _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
551+ expectedError := "invalid fileshare name because it has some special characters"
552+ assertTestResult (t , err .Error (), expectedError )
553+ })
554+
532555 t .Run ("Special characters in file share description are not allowed" , func (t * testing.T ) {
533- in .Size , in .Name , in .ProfileId , in .Description = int64 (1 ), "sample-fileshare-01 " , "b3585ebe-c42c-120g-b28e-f373746a71ca" , "#FileShare Code !$! test"
556+ in .Size , in .Name , in .ProfileId , in .Description = int64 (1 ), "test tmp " , "b3585ebe-c42c-120g-b28e-f373746a71ca" , "#Share !$!test"
534557 mockClient := new (dbtest.Client )
535558 mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
559+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (nil , nil )
536560 db .C = mockClient
537561
538562 _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
539563 expectedError := "invalid fileshare description and it has some special characters"
540564 assertTestResult (t , err .Error (), expectedError )
541565 })
566+
567+ t .Run ("Duplicate file share name are not allowed" , func (t * testing.T ) {
568+ var sampleshares = []* model.FileShareSpec {& SampleFileShares [0 ]}
569+ in .Size , in .Name , in .ProfileId , in .Description = int64 (1 ), "samplefileshare01" , "b3585ebe-c42c-120g-b28e-f373746a71ca" , "File share test"
570+ mockClient := new (dbtest.Client )
571+ mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
572+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (sampleshares , nil )
573+ db .C = mockClient
574+
575+ _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
576+ expectedError := "file share name already exists"
577+ assertTestResult (t , err .Error (), expectedError )
578+ })
579+
580+ t .Run ("Overwritting existing file share resource are not allowed" , func (t * testing.T ) {
581+ var sampleshares = []* model.FileShareSpec {& SampleFileShares [0 ]}
582+ in .Size , in .Name , in .ProfileId , in .Description , in .Id = int64 (1 ), "samplefileshare05" , "b3585ebe-c42c-120g-b28e-f373746a71ca" , "File share test" , "d2975ebe-d82c-430f-b28e-f373746a71ca"
583+ mockClient := new (dbtest.Client )
584+ mockClient .On ("CreateFileShare" , context .NewAdminContext (), in ).Return (& SampleFileShares [0 ], nil )
585+ mockClient .On ("ListFileShares" , context .NewAdminContext ()).Return (sampleshares , nil )
586+ db .C = mockClient
587+
588+ _ , err := CreateFileShareDBEntry (context .NewAdminContext (), in )
589+ expectedError := "file share id already exists"
590+ assertTestResult (t , err .Error (), expectedError )
591+ })
542592}
543593
544594func TestDeleteFileShareDBEntry (t * testing.T ) {
0 commit comments