Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration test cases of file share #1037

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/fileshare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestCreateFileShareAcl(t *testing.T) {
t.Error(err)
return
}

fileShareAcl.Status = "available"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should our test case include FielShareAcl.Statu = "unavailable" to for Create File Share ACL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only positive scenarios are covered in this cycle of execution. FileshareAcl.Status = "error" is there not "unavailable"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a test case for unavailable test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

if !reflect.DeepEqual(fileShareAcl, &SampleFileSharesAcl[0]) {
t.Errorf("expected %+v, got %+v", &SampleFileSharesAcl[0], fileShareAcl)
return
Expand Down
14 changes: 7 additions & 7 deletions pkg/api/controllers/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,15 @@ func TestDeleteFileShareProfile(t *testing.T) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check if the new profile API (though it is just param changes), will have any effect on this?

t.Run("Should return 200 if everything works well", func(t *testing.T) {
mockClient := new(dbtest.Client)
mockClient.On("GetProfile", c.NewAdminContext(), "2f9c0a04-66ef-11e7-ade2-43158893e017").Return(
mockClient.On("GetProfile", c.NewAdminContext(), "3f9c0a04-66ef-11e7-ade2-43158893e017").Return(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the ID change required for tests? Should not it be consistent or some generator which generates ID and that is persisted across the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are all compulsorily needed to mock functions GetProfile function, it was using block profile, So now i have changed to use file profiles.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are only for ID..Why tests should have changes related to ID..Shoud we have generator function for ID which can be used across the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data collection file is already there, we are reusing those. In this test case it was using block profile. So we have changed to file profile id

&SampleFileShareProfiles[1], nil)
mockClient.On("ListFileSharesByProfileId", c.NewAdminContext(), "2f9c0a04-66ef-11e7-ade2-43158893e017").Return(
mockClient.On("ListFileSharesByProfileId", c.NewAdminContext(), "3f9c0a04-66ef-11e7-ade2-43158893e017").Return(
SampleShareNames, nil)
mockClient.On("DeleteProfile", c.NewAdminContext(), "2f9c0a04-66ef-11e7-ade2-43158893e017").Return(nil)
mockClient.On("DeleteProfile", c.NewAdminContext(), "3f9c0a04-66ef-11e7-ade2-43158893e017").Return(nil)
db.C = mockClient

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

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

r, _ := http.NewRequest("DELETE",
"/v1beta/profiles/2f9c0a04-66ef-11e7-ade2-43158893e017", nil)
"/v1beta/profiles/3f9c0a04-66ef-11e7-ade2-43158893e017", nil)
w := httptest.NewRecorder()
beego.InsertFilter("*", beego.BeforeExec, func(httpCtx *context.Context) {
httpCtx.Input.SetData("context", c.NewAdminContext())
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/fileshare/filesharecontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestCreateFileShareAcl(t *testing.T) {
if err != nil {
t.Errorf("failed to create fileshare acl, err is %v\n", err)
}

result.Status = "available"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, Should we have a test case for unavailable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only +ve scenarios covered for IT

if !reflect.DeepEqual(result, expected) {
t.Errorf("expected %v, got %v\n", expected, result)
}
Expand Down
255 changes: 255 additions & 0 deletions test/integration/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,258 @@ func TestClientFailoverReplication(t *testing.T) {
t.Log("Disable volume replication not ready!")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not this file be separated for different features? like client_fs_test, client_block_test , client_relication_test....?
@joseph-v @Shruthi-1MN Can we please consider this?

*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this client_test.go be seggregated into different clients? Cleints for File, Block, Replication etc...


/*
File share integration test cases
*/

func TestClientCreateFileProfile(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function should be split and one part should be made generic. Just pass the StorageType as Block, File or Object..It should create profile with the cutomeProperties. Caller will then do the match with the expected

var body = &model.ProfileSpec{
Name: "gold",
Description: "gold policy",
StorageType: "file",
}

prf, err := c.CreateProfile(body)
if err != nil {
t.Error("create profile in client failed:", err)
return
}
// If customized properties are not defined, create an empty one.
if prf.CustomProperties == nil {
prf.CustomProperties = model.CustomPropertiesSpec{}
}

var expected = &SampleFileShareProfiles[0]
if !reflect.DeepEqual(prf, expected) {
t.Errorf("expected %+v, got %+v\n", expected, prf)
}
}

func TestClientGetFileProfile(t *testing.T) {
var prfID = "3f9c0a04-66ef-11e7-ade2-43158893e017"

prf, err := c.GetProfile(prfID)
if err != nil {
t.Error("get profile in client failed:", err)
return
}

var expected = &SampleFileShareProfiles[1]
if !reflect.DeepEqual(prf, expected) {
t.Errorf("expected %+v, got %+v\n", expected, prf)
}
}

func TestClientCreateFileShare(t *testing.T) {
var body = &model.FileShareSpec{
Name: "test",
Description: "This is a test",
Size: int64(1),
ProfileId: "2106b972-66ef-11e7-b172-db03f3689c9c",
}

if _, err := c.CreateFileShare(body); err != nil {
t.Error("create file share in client failed:", err)
return
}

t.Log("Create file share success!")
}

func TestClientGetFileShare(t *testing.T) {
var fileshareID = "d2975ebe-d82c-430f-b28e-f373746a71ca"

fileshare, err := c.GetFileShare(fileshareID)
if err != nil {
t.Error("get file share in client failed:", err)
return
}

var expected = &SampleFileShares[0]
if !reflect.DeepEqual(fileshare, expected) {
t.Errorf("expected %+v, got %+v\n", expected, fileshare)
}
}

func TestClientListFileShares(t *testing.T) {
fileshares, err := c.ListFileShares()
if err != nil {
t.Error("list fileshares in client failed:", err)
return
}

var expected []*model.FileShareSpec
for i := range SampleFileShares {
expected = append(expected, &SampleFileShares[i])
}
if !reflect.DeepEqual(fileshares, expected) {
t.Errorf("expected %+v, got %+v\n", expected, fileshares)
}
}

func TestClientUpdateFileShare(t *testing.T) {
var fileshareID = "d2975ebe-d82c-430f-b28e-f373746a71ca"
body := &model.FileShareSpec{
Name: "sample-fileshare-01",
Description: "This is first sample fileshare for testing",
}

fileshare, err := c.UpdateFileShare(fileshareID, body)
if err != nil {
t.Error("update fileshare in client failed:", err)
return
}

var expected = &SampleFileShares[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the expected value an array or struct or just a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its interface

if !reflect.DeepEqual(fileshare, expected) {
t.Errorf("expected %+v, got %+v\n", expected, fileshare)
}
}

func TestClientCreateFileShareAcl(t *testing.T) {
var body = &model.FileShareAclSpec{
Description: "This is a sample Acl for testing",
ProfileId: "3f9c0a04-66ef-11e7-ade2-43158893e017",
Type: "ip",
AccessCapability: []string{"Read", "Write"},
AccessTo: "10.32.109.15",
FileShareId: "d2975ebe-d82c-430f-b28e-f373746a71ca",
}

if _, err := c.CreateFileShareAcl(body); err != nil {
t.Error("create file share acl in client failed:", err)
return
}

t.Log("Create file share acl success!")
}

func TestClientGetFileShareAcl(t *testing.T) {
var aclID = "d2975ebe-d82c-430f-b28e-f373746a71ca"

acl, err := c.GetFileShareAcl(aclID)
if err != nil {
t.Error("get file share acl in client failed:", err)
return
}

var expected = &SampleFileSharesAcl[0]
if !reflect.DeepEqual(acl, expected) {
t.Errorf("expected %+v, got %+v\n", expected, acl)
}
}

func TestClientListFileShareAcl(t *testing.T) {
acls, err := c.ListFileSharesAcl()
if err != nil {
t.Error("list fileshare acls in client failed:", err)
return
}

var expected []*model.FileShareAclSpec
for i := range SampleFileSharesAcl {
expected = append(expected, &SampleFileSharesAcl[i])
}
if !reflect.DeepEqual(acls, expected) {
t.Errorf("expected %+v, got %+v\n", expected, acls)
}
}

func TestClientCreateFileShareSnapshot(t *testing.T) {
var body = &model.FileShareSnapshotSpec{
Name: "test",
Description: "This is a test",
FileShareId: "d2975ebe-d82c-430f-b28e-f373746a71ca",
}

if _, err := c.CreateFileShareSnapshot(body); err != nil {
t.Error("create file share snapshot in client failed:", err)
return
}

t.Log("Create file share snapshot success!")
}

func TestClientGetFileShareSnapshot(t *testing.T) {
var snpID = "3769855c-a102-11e7-b772-17b880d2f537"

snp, err := c.GetFileShareSnapshot(snpID)
if err != nil {
t.Error("get file share snapshot in client failed:", err)
return
}

var expected = &SampleFileShareSnapshots[0]
if !reflect.DeepEqual(snp, expected) {
t.Errorf("expected %+v, got %+v\n", expected, snp)
}
}

func TestClientListFileShareSnapshots(t *testing.T) {
snps, err := c.ListFileShareSnapshots()
if err != nil {
t.Error("list file share snapshots in client failed:", err)
return
}

var expected []*model.FileShareSnapshotSpec
for i := range SampleFileShareSnapshots {
expected = append(expected, &SampleFileShareSnapshots[i])
}
if !reflect.DeepEqual(snps, expected) {
t.Errorf("expected %+v, got %+v\n", expected, snps)
}
}

func TestClientUpdateFileShareSnapshot(t *testing.T) {
var snpID = "3769855c-a102-11e7-b772-17b880d2f537"
body := &model.FileShareSnapshotSpec{
Name: "sample-snapshot-01",
Description: "This is the first sample snapshot for testing",
}

snp, err := c.UpdateFileShareSnapshot(snpID, body)
if err != nil {
t.Error("update file share snapshot in client failed:", err)
return
}

var expected = &SampleFileShareSnapshots[0]
if !reflect.DeepEqual(snp, expected) {
t.Errorf("expected %+v, got %+v\n", expected, snp)
}
}

func TestClientDeleteFileShareAcl(t *testing.T) {
var fileshareaclID = "d2975ebe-d82c-430f-b28e-f373746a71ca"

if err := c.DeleteFileShareAcl(fileshareaclID); err != nil {
t.Error("delete file share acl in client failed:", err)
return
}

t.Log("Delete file share acl success!")
}

func TestClientDeleteFileShareSnapshot(t *testing.T) {
var snapID = "3769855c-a102-11e7-b772-17b880d2f537"

if err := c.DeleteFileShareSnapshot(snapID); err != nil {
t.Error("delete file share snapshot in client failed:", err)
return
}

t.Log("Delete file share snapshot success!")
}

func TestClientDeleteFileProfile(t *testing.T) {
var prfID = "2f9c0a04-66ef-11e7-ade2-43158893e017"

if err := c.DeleteProfile(prfID); err != nil {
t.Error("delete profile in client failed:", err)
return
}

t.Log("Delete profile success!")
}
Loading