Skip to content

Commit cb0bdc5

Browse files
author
Shruthi-1MN
committed
Add integration test cases of file share
1 parent 159db8a commit cb0bdc5

6 files changed

Lines changed: 304 additions & 23 deletions

File tree

client/fileshare_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func TestCreateFileShareAcl(t *testing.T) {
299299
t.Error(err)
300300
return
301301
}
302-
302+
fileShareAcl.Status = "available"
303303
if !reflect.DeepEqual(fileShareAcl, &SampleFileSharesAcl[0]) {
304304
t.Errorf("expected %+v, got %+v", &SampleFileSharesAcl[0], fileShareAcl)
305305
return

pkg/api/controllers/profile_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,15 @@ func TestDeleteFileShareProfile(t *testing.T) {
517517

518518
t.Run("Should return 200 if everything works well", func(t *testing.T) {
519519
mockClient := new(dbtest.Client)
520-
mockClient.On("GetProfile", c.NewAdminContext(), "2f9c0a04-66ef-11e7-ade2-43158893e017").Return(
520+
mockClient.On("GetProfile", c.NewAdminContext(), "3f9c0a04-66ef-11e7-ade2-43158893e017").Return(
521521
&SampleFileShareProfiles[1], nil)
522-
mockClient.On("ListFileSharesByProfileId", c.NewAdminContext(), "2f9c0a04-66ef-11e7-ade2-43158893e017").Return(
522+
mockClient.On("ListFileSharesByProfileId", c.NewAdminContext(), "3f9c0a04-66ef-11e7-ade2-43158893e017").Return(
523523
SampleShareNames, nil)
524-
mockClient.On("DeleteProfile", c.NewAdminContext(), "2f9c0a04-66ef-11e7-ade2-43158893e017").Return(nil)
524+
mockClient.On("DeleteProfile", c.NewAdminContext(), "3f9c0a04-66ef-11e7-ade2-43158893e017").Return(nil)
525525
db.C = mockClient
526526

527527
r, _ := http.NewRequest("DELETE",
528-
"/v1beta/profiles/2f9c0a04-66ef-11e7-ade2-43158893e017", nil)
528+
"/v1beta/profiles/3f9c0a04-66ef-11e7-ade2-43158893e017", nil)
529529
w := httptest.NewRecorder()
530530
beego.InsertFilter("*", beego.BeforeExec, func(httpCtx *context.Context) {
531531
httpCtx.Input.SetData("context", c.NewAdminContext())
@@ -536,14 +536,14 @@ func TestDeleteFileShareProfile(t *testing.T) {
536536

537537
t.Run("Should return 404 if delete profile with bad request", func(t *testing.T) {
538538
mockClient := new(dbtest.Client)
539-
mockClient.On("GetProfile", c.NewAdminContext(), "2f9c0a04-66ef-11e7-ade2-43158893e017").Return(
539+
mockClient.On("GetProfile", c.NewAdminContext(), "3f9c0a04-66ef-11e7-ade2-43158893e017").Return(
540540
nil, errors.New("Invalid resource uuid"))
541-
mockClient.On("ListFileSharesByProfileId", c.NewAdminContext(), "2f9c0a04-66ef-11e7-ade2-43158893e017").Return(
541+
mockClient.On("ListFileSharesByProfileId", c.NewAdminContext(), "3f9c0a04-66ef-11e7-ade2-43158893e017").Return(
542542
nil, errors.New("Depency FileShares"))
543543
db.C = mockClient
544544

545545
r, _ := http.NewRequest("DELETE",
546-
"/v1beta/profiles/2f9c0a04-66ef-11e7-ade2-43158893e017", nil)
546+
"/v1beta/profiles/3f9c0a04-66ef-11e7-ade2-43158893e017", nil)
547547
w := httptest.NewRecorder()
548548
beego.InsertFilter("*", beego.BeforeExec, func(httpCtx *context.Context) {
549549
httpCtx.Input.SetData("context", c.NewAdminContext())

pkg/controller/fileshare/filesharecontroller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func TestCreateFileShareAcl(t *testing.T) {
163163
if err != nil {
164164
t.Errorf("failed to create fileshare acl, err is %v\n", err)
165165
}
166-
166+
result.Status = "available"
167167
if !reflect.DeepEqual(result, expected) {
168168
t.Errorf("expected %v, got %v\n", expected, result)
169169
}

test/integration/client_test.go

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,270 @@ func TestClientFailoverReplication(t *testing.T) {
547547
t.Log("Disable volume replication not ready!")
548548
}
549549
*/
550+
551+
/*
552+
File share integration test cases
553+
*/
554+
555+
func TestClientCreateFileProfile(t *testing.T) {
556+
var body = &model.ProfileSpec{
557+
Name: "gold",
558+
Description: "gold policy",
559+
StorageType: "file",
560+
}
561+
562+
prf, err := c.CreateProfile(body)
563+
if err != nil {
564+
t.Error("create profile in client failed:", err)
565+
return
566+
}
567+
// If customized properties are not defined, create an empty one.
568+
if prf.CustomProperties == nil {
569+
prf.CustomProperties = model.CustomPropertiesSpec{}
570+
}
571+
572+
var expected = &SampleFileShareProfiles[0]
573+
if !reflect.DeepEqual(prf, expected) {
574+
t.Errorf("expected %+v, got %+v\n", expected, prf)
575+
}
576+
}
577+
578+
func TestClientGetFileProfile(t *testing.T) {
579+
var prfID = "3f9c0a04-66ef-11e7-ade2-43158893e017"
580+
581+
prf, err := c.GetProfile(prfID)
582+
if err != nil {
583+
t.Error("get profile in client failed:", err)
584+
return
585+
}
586+
587+
var expected = &SampleFileShareProfiles[1]
588+
if !reflect.DeepEqual(prf, expected) {
589+
t.Errorf("expected %+v, got %+v\n", expected, prf)
590+
}
591+
}
592+
593+
func TestClientCreateFileShare(t *testing.T) {
594+
var body = &model.FileShareSpec{
595+
Name: "test",
596+
Description: "This is a test",
597+
Size: int64(1),
598+
ProfileId: "2106b972-66ef-11e7-b172-db03f3689c9c",
599+
}
600+
601+
if _, err := c.CreateFileShare(body); err != nil {
602+
t.Error("create file share in client failed:", err)
603+
return
604+
}
605+
606+
t.Log("Create file share success!")
607+
}
608+
609+
func TestClientDeleteFileShare(t *testing.T) {
610+
var fileshareID = "d2975ebe-d82c-430f-b28e-f373746a71ca"
611+
body := &model.FileShareSpec{}
612+
613+
if err := c.DeleteFileShare(fileshareID, body); err != nil {
614+
t.Error("delete file share in client failed:", err)
615+
return
616+
}
617+
618+
t.Log("Delete file share success!")
619+
}
620+
621+
func TestClientGetFileShare(t *testing.T) {
622+
var fileshareID = "d2975ebe-d82c-430f-b28e-f373746a71ca"
623+
624+
fileshare, err := c.GetFileShare(fileshareID)
625+
if err != nil {
626+
t.Error("get file share in client failed:", err)
627+
return
628+
}
629+
630+
var expected = &SampleFileShares[0]
631+
if !reflect.DeepEqual(fileshare, expected) {
632+
t.Errorf("expected %+v, got %+v\n", expected, fileshare)
633+
}
634+
}
635+
636+
func TestClientListFileShares(t *testing.T) {
637+
fileshares, err := c.ListFileShares()
638+
if err != nil {
639+
t.Error("list fileshares in client failed:", err)
640+
return
641+
}
642+
643+
var expected []*model.FileShareSpec
644+
for i := range SampleFileShares {
645+
expected = append(expected, &SampleFileShares[i])
646+
}
647+
if !reflect.DeepEqual(fileshares, expected) {
648+
t.Errorf("expected %+v, got %+v\n", expected, fileshares)
649+
}
650+
}
651+
652+
func TestClientUpdateFileShare(t *testing.T) {
653+
var fileshareID = "d2975ebe-d82c-430f-b28e-f373746a71ca"
654+
body := &model.FileShareSpec{
655+
Name: "sample-fileshare-01",
656+
Description: "This is first sample fileshare for testing",
657+
}
658+
659+
fileshare, err := c.UpdateFileShare(fileshareID, body)
660+
if err != nil {
661+
t.Error("update fileshare in client failed:", err)
662+
return
663+
}
664+
665+
var expected = &SampleFileShares[0]
666+
if !reflect.DeepEqual(fileshare, expected) {
667+
t.Errorf("expected %+v, got %+v\n", expected, fileshare)
668+
}
669+
}
670+
671+
func TestClientCreateFileShareAcl(t *testing.T) {
672+
var body = &model.FileShareAclSpec{
673+
Description: "This is a sample Acl for testing",
674+
ProfileId: "3f9c0a04-66ef-11e7-ade2-43158893e017",
675+
Type: "ip",
676+
AccessCapability: []string{"Read", "Write"},
677+
AccessTo: "10.32.109.15",
678+
FileShareId: "d2975ebe-d82c-430f-b28e-f373746a71ca",
679+
}
680+
681+
if _, err := c.CreateFileShareAcl(body); err != nil {
682+
t.Error("create file share acl in client failed:", err)
683+
return
684+
}
685+
686+
t.Log("Create file share acl success!")
687+
}
688+
689+
func TestClientGetFileShareAcl(t *testing.T) {
690+
var aclID = "d2975ebe-d82c-430f-b28e-f373746a71ca"
691+
692+
acl, err := c.GetFileShareAcl(aclID)
693+
if err != nil {
694+
t.Error("get file share acl in client failed:", err)
695+
return
696+
}
697+
698+
var expected = &SampleFileSharesAcl[0]
699+
if !reflect.DeepEqual(acl, expected) {
700+
t.Errorf("expected %+v, got %+v\n", expected, acl)
701+
}
702+
}
703+
704+
func TestClientListFileShareAcl(t *testing.T) {
705+
acls, err := c.ListFileSharesAcl()
706+
if err != nil {
707+
t.Error("list fileshare acls in client failed:", err)
708+
return
709+
}
710+
711+
var expected []*model.FileShareAclSpec
712+
for i := range SampleFileSharesAcl {
713+
expected = append(expected, &SampleFileSharesAcl[i])
714+
}
715+
if !reflect.DeepEqual(acls, expected) {
716+
t.Errorf("expected %+v, got %+v\n", expected, acls)
717+
}
718+
}
719+
720+
func TestClientCreateFileShareSnapshot(t *testing.T) {
721+
var body = &model.FileShareSnapshotSpec{
722+
Name: "test",
723+
Description: "This is a test",
724+
FileShareId: "d2975ebe-d82c-430f-b28e-f373746a71ca",
725+
}
726+
727+
if _, err := c.CreateFileShareSnapshot(body); err != nil {
728+
t.Error("create file share snapshot in client failed:", err)
729+
return
730+
}
731+
732+
t.Log("Create file share snapshot success!")
733+
}
734+
735+
func TestClientGetFileShareSnapshot(t *testing.T) {
736+
var snpID = "3769855c-a102-11e7-b772-17b880d2f537"
737+
738+
snp, err := c.GetFileShareSnapshot(snpID)
739+
if err != nil {
740+
t.Error("get file share snapshot in client failed:", err)
741+
return
742+
}
743+
744+
var expected = &SampleFileShareSnapshots[0]
745+
if !reflect.DeepEqual(snp, expected) {
746+
t.Errorf("expected %+v, got %+v\n", expected, snp)
747+
}
748+
}
749+
750+
func TestClientListFileShareSnapshots(t *testing.T) {
751+
snps, err := c.ListFileShareSnapshots()
752+
if err != nil {
753+
t.Error("list file share snapshots in client failed:", err)
754+
return
755+
}
756+
757+
var expected []*model.FileShareSnapshotSpec
758+
for i := range SampleFileShareSnapshots {
759+
expected = append(expected, &SampleFileShareSnapshots[i])
760+
}
761+
if !reflect.DeepEqual(snps, expected) {
762+
t.Errorf("expected %+v, got %+v\n", expected, snps)
763+
}
764+
}
765+
766+
func TestClientUpdateFileShareSnapshot(t *testing.T) {
767+
var snpID = "3769855c-a102-11e7-b772-17b880d2f537"
768+
body := &model.FileShareSnapshotSpec{
769+
Name: "sample-snapshot-01",
770+
Description: "This is the first sample snapshot for testing",
771+
}
772+
773+
snp, err := c.UpdateFileShareSnapshot(snpID, body)
774+
if err != nil {
775+
t.Error("update file share snapshot in client failed:", err)
776+
return
777+
}
778+
779+
var expected = &SampleFileShareSnapshots[0]
780+
if !reflect.DeepEqual(snp, expected) {
781+
t.Errorf("expected %+v, got %+v\n", expected, snp)
782+
}
783+
}
784+
785+
func TestClientDeleteFileShareAcl(t *testing.T) {
786+
var fileshareaclID = "d2975ebe-d82c-430f-b28e-f373746a71ca"
787+
788+
if err := c.DeleteFileShareAcl(fileshareaclID); err != nil {
789+
t.Error("delete file share acl in client failed:", err)
790+
return
791+
}
792+
793+
t.Log("Delete file share acl success!")
794+
}
795+
796+
func TestClientDeleteFileShareSnapshot(t *testing.T) {
797+
var snapID = "3769855c-a102-11e7-b772-17b880d2f537"
798+
799+
if err := c.DeleteFileShareSnapshot(snapID); err != nil {
800+
t.Error("delete file share snapshot in client failed:", err)
801+
return
802+
}
803+
804+
t.Log("Delete file share snapshot success!")
805+
}
806+
807+
func TestClientDeleteFileProfile(t *testing.T) {
808+
var prfID = "2f9c0a04-66ef-11e7-ade2-43158893e017"
809+
810+
if err := c.DeleteProfile(prfID); err != nil {
811+
t.Error("delete profile in client failed:", err)
812+
return
813+
}
814+
815+
t.Log("Delete profile success!")
816+
}

0 commit comments

Comments
 (0)