Skip to content

Commit

Permalink
Merge pull request #970 from Shruthi-1MN/controller-ut
Browse files Browse the repository at this point in the history
Fileshare controller unit test cases
  • Loading branch information
skdwriting committed Aug 14, 2019
2 parents fdb32c2 + ca23865 commit 30487b3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/api/util/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func TestDeleteFileShareDBEntry(t *testing.T) {
assertTestResult(t, err.Error(), expectedError)
})

var sampleAcls = []*model.FileShareAclSpec{&SampleSharesAcl[0]}
var sampleAcls = []*model.FileShareAclSpec{&SampleFileSharesAcl[2]}
t.Run("FileShare should not be deleted if it has dependent acls", func(t *testing.T) {
//in.Status = model.FileShareAvailable
fileshare.Status = model.FileShareAvailable
Expand Down
47 changes: 47 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,4 +785,51 @@ func TestDeleteFileShareSnapshot(t *testing.T) {
if _, err := ctrl.DeleteFileShareSnapshot(context.Background(), req); err != nil {
t.Errorf("failed to delete file share snapshot: %v\n", err)
}
}

func TestCreateFileShareAcl(t *testing.T) {
var req = &pb.CreateFileShareAclOpts{
Id: "6ad25d59-a160-45b2-8920-211be282e2df",
Description: "This is a sample Acl for testing",
Type: "ip",
AccessCapability: []string{"Read", "Write"},
AccessTo: "10.32.109.15",
FileshareId: "d2975ebe-d82c-430f-b28e-f373746a71ca",
Context: c.NewAdminContext().ToJson(),
}
var fileshare = &SampleFileShares[0]
var acl = &SampleFileSharesAcl[0]
mockClient := new(dbtest.Client)
mockClient.On("GetFileShare", c.NewAdminContext(), req.FileshareId).Return(fileshare, nil)
mockClient.On("GetDockByPoolId", c.NewAdminContext(), fileshare.PoolId).Return(&SampleDocks[0], nil)
mockClient.On("UpdateStatus", c.NewAdminContext(), acl, "available").Return(nil)
db.C = mockClient

var ctrl = &Controller{
fileshareController: NewFakeFileShareController(),
}
if _, err := ctrl.CreateFileShareAcl(context.Background(), req); err != nil {
t.Errorf("failed to create file share snapshot: %v\n", err)
}
}

func TestDeleteFileShareAcl(t *testing.T) {
var req = &pb.DeleteFileShareAclOpts{
Id: "3769855c-a102-11e7-b772-17b880d2f537",
FileshareId: "bd5b12a8-a101-11e7-941e-d77981b584d8",
Context: c.NewAdminContext().ToJson(),
}
var fileshare = &SampleShares[0]
mockClient := new(dbtest.Client)
mockClient.On("GetFileShare", c.NewAdminContext(), req.FileshareId).Return(fileshare, nil)
mockClient.On("GetDockByPoolId", c.NewAdminContext(), fileshare.PoolId).Return(&SampleDocks[0], nil)
mockClient.On("DeleteFileShareAcl", c.NewAdminContext(), req.Id).Return(nil)
db.C = mockClient

var ctrl = &Controller{
fileshareController: NewFakeFileShareController(),
}
if _, err := ctrl.DeleteFileShareAcl(context.Background(), req); err != nil {
t.Errorf("failed to delete file share snapshot: %v\n", err)
}
}
28 changes: 13 additions & 15 deletions testutils/collection/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,31 +243,29 @@ var (
},
Description: "This is a sample Acl for testing",
},
}
SampleSharesAcl = []model.FileShareAclSpec{
{
BaseModel: &model.BaseModel{
Id: "d2975ebe-d82c-430f-b28e-f373746a71ca",
Id: "6ad25d59-a160-45b2-8920-211be282e2df",
},
Status: "available",
FileShareId: "bd5b12a8-a101-11e7-941e-d77981b584d8",
ProfileId: "3769855c-a102-11e7-b772-17b880d2f537",
Type: "ip",
AccessTo: "10.21.23.10",
AccessCapability:[]string{"Read", "Write"},
Description: "This is a sample Acl for testing",
Type: "ip",
AccessCapability: []string{"Read", "Write"},
AccessTo: "10.32.109.15",
FileShareId: "d2975ebe-d82c-430f-b28e-f373746a71ca",
},
{
BaseModel: &model.BaseModel{
Id: "1e643aca-4922-4b1a-bb98-4245054aeff4",
Id: "ad25d59-a160-45b2-8920-211be282e2dfh",
},
Status: "available",
FileShareId: "bd5b12a8-a101-11e7-941e-d77981b584d8",
ProfileId: "3769855c-a102-11e7-b772-17b880d2f537",
Description: "This is a sample Acl for testing",
ProfileId: "1106b972-66ef-11e7-b172-db03f3689c9c",
Type: "ip",
AccessTo: "101.21.23.10",
AccessCapability:[]string{"Read"},
AccessCapability: []string{"Read", "Write"},
AccessTo: "10.32.109.151",
FileShareId: "d2975ebe-d82c-430f-b28e-f373746a71ca",
},
}

SampleFileShareSnapshots = []model.FileShareSnapshotSpec{
{
BaseModel: &model.BaseModel{
Expand Down

0 comments on commit 30487b3

Please sign in to comment.