Skip to content

Commit

Permalink
Add fileshare controller unit test cases for create/delete fileshare …
Browse files Browse the repository at this point in the history
…and create/delete filesharesnapshots
  • Loading branch information
Shruthi-1MN committed May 29, 2019
1 parent 7377b2e commit 58dee1f
Show file tree
Hide file tree
Showing 2 changed files with 294 additions and 0 deletions.
217 changes: 217 additions & 0 deletions pkg/controller/fileshare/filesharecontroller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
// Copyright 2019 The OpenSDS Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package fileshare

import (
"context"
"reflect"
"testing"

"github.com/opensds/opensds/pkg/dock/client"
"github.com/opensds/opensds/pkg/model"
pb "github.com/opensds/opensds/pkg/model/proto"
. "github.com/opensds/opensds/testutils/collection"
"google.golang.org/grpc"
)

type fakefileshareClient struct{}

func NewFakeClient() client.Client {
return &fakefileshareClient{}
}

func (fc *fakefileshareClient) Connect(edp string) error {
return nil
}

func (fc *fakefileshareClient) Close() {
return
}

func (fc *fakefileshareClient) CreateFileShare(ctx context.Context, in *pb.CreateFileShareOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return &pb.GenericResponse{
Reply: &pb.GenericResponse_Result_{
Result: &pb.GenericResponse_Result{
Message: ByteFileShare,
},
},
}, nil
}

func (fc *fakefileshareClient) CreateFileShareAcl(ctx context.Context, in *pb.CreateFileShareAclOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return &pb.GenericResponse{
Reply: &pb.GenericResponse_Result_{
Result: &pb.GenericResponse_Result{
Message: ByteFileShareAcl,
},
},
}, nil
}

// DeleteFileShare provides a mock function with given fields: ctx, in, opts
func (fc *fakefileshareClient) DeleteFileShare(ctx context.Context, in *pb.DeleteFileShareOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return &pb.GenericResponse{
Reply: &pb.GenericResponse_Result_{
Result: &pb.GenericResponse_Result{
Message: ByteFileShare,
},
},
}, nil
}

func (fc *fakefileshareClient) CreateFileShareSnapshot(ctx context.Context, in *pb.CreateFileShareSnapshotOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return &pb.GenericResponse{
Reply: &pb.GenericResponse_Result_{
Result: &pb.GenericResponse_Result{
Message: ByteFileShareSnapshot,
},
},
}, nil
}

func (fc *fakefileshareClient) DeleteFileShareSnapshot(ctx context.Context, in *pb.DeleteFileShareSnapshotOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return &pb.GenericResponse{
Reply: &pb.GenericResponse_Result_{
Result: &pb.GenericResponse_Result{
Message: ByteFileShareSnapshot,
},
},
}, nil
}

func NewFakeController() Controller {
return &controller{
Client: NewFakeClient(),
DockInfo: &model.DockSpec{},
}
}

func TestCreateFileShare(t *testing.T) {
fc := NewFakeController()
var expected = &SampleShares[0]

result, err := fc.CreateFileShare(&pb.CreateFileShareOpts{})
if err != nil {
t.Errorf("failed to create fileshare, err is %v\n", err)
}

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

func TestDeleteFileShare(t *testing.T) {
fc := NewFakeController()

result := fc.DeleteFileShare(&pb.DeleteFileShareOpts{})
if result != nil {
t.Errorf("expected %v, got %v\n", nil, result)
}
}

func TestCreateFileShareSnapshot(t *testing.T) {
fc := NewFakeController()
var expected = &SampleShareSnapshots[0]

result, err := fc.CreateFileShareSnapshot(&pb.CreateFileShareSnapshotOpts{})
if err != nil {
t.Errorf("failed to create file share snapshot, err is %v\n", err)
}

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

func TestDeleteFileShareSnapshot(t *testing.T) {
fc := NewFakeController()

result := fc.DeleteFileShareSnapshot(&pb.DeleteFileShareSnapshotOpts{})
if result != nil {
t.Errorf("expected %v, got %v\n", nil, result)
}
}

func (fc *fakefileshareClient) CreateVolume(ctx context.Context, in *pb.CreateVolumeOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) DeleteVolume(ctx context.Context, in *pb.DeleteVolumeOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) ExtendVolume(ctx context.Context, in *pb.ExtendVolumeOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) CreateVolumeSnapshot(ctx context.Context, in *pb.CreateVolumeSnapshotOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) DeleteVolumeSnapshot(ctx context.Context, in *pb.DeleteVolumeSnapshotOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) CreateVolumeAttachment(ctx context.Context, in *pb.CreateVolumeAttachmentOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) DeleteVolumeAttachment(ctx context.Context, in *pb.DeleteVolumeAttachmentOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) CreateReplication(ctx context.Context, in *pb.CreateReplicationOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) DeleteReplication(ctx context.Context, in *pb.DeleteReplicationOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) EnableReplication(ctx context.Context, in *pb.EnableReplicationOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) DisableReplication(ctx context.Context, in *pb.DisableReplicationOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) FailoverReplication(ctx context.Context, in *pb.FailoverReplicationOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) CreateVolumeGroup(ctx context.Context, in *pb.CreateVolumeGroupOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) UpdateVolumeGroup(ctx context.Context, in *pb.UpdateVolumeGroupOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) DeleteVolumeGroup(ctx context.Context, in *pb.DeleteVolumeGroupOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) CollectMetrics(ctx context.Context, in *pb.CollectMetricsOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) AttachVolume(ctx context.Context, in *pb.AttachVolumeOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}

func (fc *fakefileshareClient) DetachVolume(ctx context.Context, in *pb.DetachVolumeOpts, opts ...grpc.CallOption) (*pb.GenericResponse, error) {
return nil, nil
}
77 changes: 77 additions & 0 deletions testutils/collection/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,33 @@ var (
},
}

SampleShares = []model.FileShareSpec{
{
BaseModel: &model.BaseModel{
Id: "bd5b12a8-a101-11e7-941e-d77981b584d8",
},
Name: "sample-fileshare",
Description: "This is a sample fileshare for testing",
Size: int64(1),
Status: "available",
PoolId: "084bf71e-a102-11e7-88a8-e31fe6d52248",
ProfileId: "1106b972-66ef-11e7-b172-db03f3689c9c",
SnapshotId: "",
},
{
BaseModel: &model.BaseModel{
Id: "bd5b12a8-a101-11e7-941e-d77981b584d8",
},
Name: "sample-fileshare",
Description: "This is a sample fileshare for testing",
Size: int64(1),
Status: "available",
PoolId: "084bf71e-a102-11e7-88a8-e31fe6d52248",
ProfileId: "1106b972-66ef-11e7-b172-db03f3689c9c",
SnapshotId: "3769855c-a102-11e7-b772-17b880d2f537",
},
}

SampleConnection = model.ConnectionInfo{
DriverVolumeType: "iscsi",
ConnectionData: map[string]interface{}{
Expand Down Expand Up @@ -317,6 +344,31 @@ var (
},
}

SampleShareSnapshots = []model.FileShareSnapshotSpec{
{
BaseModel: &model.BaseModel{
Id: "3769855c-a102-11e7-b772-17b880d2f537",
},
Name: "sample-snapshot-01",
Description: "This is the first sample snapshot for testing",
ShareSize: int64(1),
Status: "available",
FileShareId: "bd5b12a8-a101-11e7-941e-d77981b584d8",
ProfileId: "1106b972-66ef-11e7-b172-db03f3689c9c",
},
{
BaseModel: &model.BaseModel{
Id: "3bfaf2cc-a102-11e7-8ecb-63aea739d755",
},
Name: "sample-snapshot-02",
Description: "This is the second sample snapshot for testing",
ShareSize: int64(1),
Status: "available",
FileShareId: "bd5b12a8-a101-11e7-941e-d77981b584d8",
ProfileId: "1106b972-66ef-11e7-b172-db03f3689c9c",
},
}

SampleReplications = []model.ReplicationSpec{
{
BaseModel: &model.BaseModel{
Expand Down Expand Up @@ -496,6 +548,31 @@ var (
}
]`

ByteFileShare = `{
"id": "bd5b12a8-a101-11e7-941e-d77981b584d8",
"name": "sample-fileshare",
"description": "This is a sample fileshare for testing",
"size": 1,
"status": "available",
"poolId": "084bf71e-a102-11e7-88a8-e31fe6d52248",
"profileId": "1106b972-66ef-11e7-b172-db03f3689c9c"
}`

ByteFileShareSnapshot = `{
"id": "3769855c-a102-11e7-b772-17b880d2f537",
"name": "sample-snapshot-01",
"description": "This is the first sample snapshot for testing",
"sharesize": 1,
"status": "available",
"fileshareId": "bd5b12a8-a101-11e7-941e-d77981b584d8",
"profileId": "1106b972-66ef-11e7-b172-db03f3689c9c"
}`

ByteFileShareAcl = `{
"id": "d2975ebe-d82c-430f-b28e-f373746a71ca",
"description": "This is a sample Acl for testing",
}`

ByteVolume = `{
"id": "bd5b12a8-a101-11e7-941e-d77981b584d8",
"name": "sample-volume",
Expand Down

0 comments on commit 58dee1f

Please sign in to comment.