From 457d3983e215569bb52b7e0ca5ea6ef0071cee93 Mon Sep 17 00:00:00 2001 From: Shruthi-1MN Date: Fri, 25 Oct 2019 13:24:52 +0530 Subject: [PATCH] Add integration test cases of file share --- test/integration/client_test.go | 264 +++++++++++++++++++++++++++- test/integration/integrationtest.sh | 0 testutils/collection/data.go | 68 +++---- testutils/db/fake.go | 19 +- 4 files changed, 316 insertions(+), 35 deletions(-) mode change 100644 => 100755 test/integration/integrationtest.sh diff --git a/test/integration/client_test.go b/test/integration/client_test.go index eac133b4a..593a4bd37 100755 --- a/test/integration/client_test.go +++ b/test/integration/client_test.go @@ -36,8 +36,8 @@ func init() { func TestClientCreateProfile(t *testing.T) { var body = &model.ProfileSpec{ - Name: "silver", - Description: "silver policy", + Name: "default", + Description: "default policy", StorageType: "block", CustomProperties: model.CustomPropertiesSpec{ "diskType": "SAS", @@ -75,6 +75,7 @@ func TestClientGetProfile(t *testing.T) { } } + func TestClientListProfiles(t *testing.T) { prfs, err := c.ListProfiles() if err != nil { @@ -92,6 +93,9 @@ func TestClientListProfiles(t *testing.T) { for i := range SampleProfiles { expected = append(expected, &SampleProfiles[i]) } + //for j := range SampleFileShareProfiles{ + // expected = append(expected, &SampleFileShareProfiles[j]) + //} if !reflect.DeepEqual(prfs, expected) { t.Errorf("expected %+v, got %+v\n", expected, prfs) } @@ -546,3 +550,259 @@ func TestClientFailoverReplication(t *testing.T) { t.Log("Disable volume replication not ready!") } */ + +/* + File share integration test cases +*/ + +func TestClientCreateFileProfile(t *testing.T) { + 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 = "a2975ebe-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 = "a2975ebe-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] + 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: "1106b972-66ef-11e7-b172-db03f3689c9c", + Type: "ip", + AccessCapability: []string{"Read", "Write"}, + AccessTo: "10.32.109.15", + FileShareId: "a2975ebe-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 = "6ad25d59-a160-45b2-8920-211be282e2df" + + acls, 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(acls, expected) { + t.Errorf("expected %+v, got %+v\n", expected, acls) + } +} + +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: "a2975ebe-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 = "3f9c0a04-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!") +} diff --git a/test/integration/integrationtest.sh b/test/integration/integrationtest.sh old mode 100644 new mode 100755 diff --git a/testutils/collection/data.go b/testutils/collection/data.go index 2af5b9597..ef2e8f454 100644 --- a/testutils/collection/data.go +++ b/testutils/collection/data.go @@ -58,19 +58,19 @@ var ( SampleFileShareProfiles = []model.ProfileSpec{ { BaseModel: &model.BaseModel{ - Id: "1106b972-66ef-11e7-b172-db03f3689c9c", + Id: "2106b972-66ef-11e7-b172-db03f3689c9c", }, - Name: "default", + Name: "default_file", Description: "default policy", StorageType: "file", CustomProperties: model.CustomPropertiesSpec{}, }, { BaseModel: &model.BaseModel{ - Id: "2f9c0a04-66ef-11e7-ade2-43158893e017", + Id: "3f9c0a04-66ef-11e7-ade2-43158893e017", }, - Name: "silver", - Description: "silver policy", + Name: "gold", + Description: "gold policy", StorageType: "file", CustomProperties: model.CustomPropertiesSpec{ "dataStorage": map[string]interface{}{ @@ -209,8 +209,8 @@ var ( Size: int64(1), Status: "available", PoolId: "a5965ebe-dg2c-434t-b28e-f373746a71ca", - ProfileId: "b3585ebe-c42c-120g-b28e-f373746a71ca", - SnapshotId: "b7602e18-771e-11e7-8f38-dbd6d291f4eg", + ProfileId: "2106b972-66ef-11e7-b172-db03f3689c9c", + //SnapshotId: "3769855c-a102-11e7-b772-17b880d2f537", AvailabilityZone: "default", ExportLocations: []string{"192.168.100.100"}, }, @@ -223,8 +223,8 @@ var ( Size: int64(1), Status: "available", PoolId: "d5f65ebe-ag2c-341s-a25e-f373746a71dr", - ProfileId: "1e643aca-4922-4b1a-bb98-4245054aeff4", - SnapshotId: "a5965ebe-dg2c-434t-b28e-f373746a71ca", + ProfileId: "3f9c0a04-66ef-11e7-ade2-43158893e017", + //SnapshotId: "3bfaf2cc-a102-11e7-8ecb-63aea739d755", AvailabilityZone: "default", ExportLocations: []string{"192.168.100.101"}, }, @@ -236,6 +236,7 @@ var ( Id: "d2975ebe-d82c-430f-b28e-f373746a71ca", }, Description: "This is a sample Acl for testing", + Status: "available", }, { BaseModel: &model.BaseModel{ @@ -243,28 +244,30 @@ var ( }, Description: "This is a sample Acl for testing", }, - { - BaseModel: &model.BaseModel{ - Id: "6ad25d59-a160-45b2-8920-211be282e2df", - }, - Description: "This is a sample Acl for testing", - ProfileId: "1106b972-66ef-11e7-b172-db03f3689c9c", - Type: "ip", - AccessCapability: []string{"Read", "Write"}, - AccessTo: "10.32.109.15", - FileShareId: "d2975ebe-d82c-430f-b28e-f373746a71ca", - }, - { - BaseModel: &model.BaseModel{ - Id: "ad25d59-a160-45b2-8920-211be282e2dfh", - }, - Description: "This is a sample Acl for testing", - ProfileId: "1106b972-66ef-11e7-b172-db03f3689c9c", - Type: "ip", - AccessCapability: []string{"Read", "Write"}, - AccessTo: "10.32.109.151", - FileShareId: "d2975ebe-d82c-430f-b28e-f373746a71ca", - }, + //{ + // BaseModel: &model.BaseModel{ + // Id: "6ad25d59-a160-45b2-8920-211be282e2df", + // }, + // Description: "This is a sample Acl for testing", + // ProfileId: "2106b972-66ef-11e7-b172-db03f3689c9c", + // Type: "ip", + // AccessCapability: []string{"Read", "Write"}, + // AccessTo: "10.32.109.15", + // Status: "available", + // FileShareId: "d2975ebe-d82c-430f-b28e-f373746a71ca", + //}, + //{ + // BaseModel: &model.BaseModel{ + // Id: "ad25d59-a160-45b2-8920-211be282e2dfh", + // }, + // Description: "This is a sample Acl for testing", + // ProfileId: "3f9c0a04-66ef-11e7-ade2-43158893e017", + // Type: "ip", + // AccessCapability: []string{"Read", "Write"}, + // AccessTo: "10.32.109.151", + // Status: "available", + // FileShareId: "1e643aca-4922-4b1a-bb98-4245054aeff4", + //}, } SampleFileShareSnapshots = []model.FileShareSnapshotSpec{ @@ -277,6 +280,7 @@ var ( SnapshotSize: int64(1), FileShareId: "d2975ebe-d82c-430f-b28e-f373746a71ca", Status: "available", + ProfileId: "2106b972-66ef-11e7-b172-db03f3689c9c", }, { BaseModel: &model.BaseModel{ @@ -285,7 +289,9 @@ var ( Name: "sample-snapshot-02", Description: "This is the second sample snapshot for testing", SnapshotSize: int64(1), + FileShareId: "1e643aca-4922-4b1a-bb98-4245054aeff4", Status: "available", + ProfileId: "3f9c0a04-66ef-11e7-ade2-43158893e017", }, } diff --git a/testutils/db/fake.go b/testutils/db/fake.go index fffedaf2c..c82f3a167 100755 --- a/testutils/db/fake.go +++ b/testutils/db/fake.go @@ -16,6 +16,7 @@ package db import ( "errors" + "fmt" c "github.com/opensds/opensds/pkg/context" "github.com/opensds/opensds/pkg/model" @@ -285,12 +286,23 @@ func (fc *FakeDbClient) DeletePool(ctx *c.Context, polID string) error { // CreateProfile func (fc *FakeDbClient) CreateProfile(ctx *c.Context, prf *model.ProfileSpec) (*model.ProfileSpec, error) { - return &SampleProfiles[0], nil + fmt.Println("Inside the fake db call....") + if prf.StorageType == "file"{ + fmt.Println("Inside file storage type check") + return &SampleFileShareProfiles[0], nil + }else{ + fmt.Println("Inside block storage type check") + return &SampleProfiles[0], nil + } } + // GetProfile func (fc *FakeDbClient) GetProfile(ctx *c.Context, prfID string) (*model.ProfileSpec, error) { - for _, profile := range SampleProfiles { + allprofiles := SampleProfiles + allprofiles = append(allprofiles, SampleFileShareProfiles[0]) + allprofiles = append(allprofiles, SampleFileShareProfiles[1]) + for _, profile := range allprofiles { if profile.Id == prfID { return &profile, nil } @@ -336,6 +348,9 @@ func (fc *FakeDbClient) ListProfiles(ctx *c.Context) ([]*model.ProfileSpec, erro for i := range SampleProfiles { prfs = append(prfs, &SampleProfiles[i]) } + //for j := range SampleFileShareProfiles { + // prfs = append(prfs, &SampleFileShareProfiles[j]) + //} return prfs, nil }