Skip to content

Commit

Permalink
Merge pull request #222 from leakingtapan/fake-clean
Browse files Browse the repository at this point in the history
Minor updates
  • Loading branch information
Cheng Pan authored Feb 21, 2019
2 parents 14b4f96 + 4051540 commit 1722563
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/cloud/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (c *FakeCloudProvider) GetDiskByName(ctx context.Context, name string, capa
if len(disks) > 1 {
return nil, ErrMultiDisks
} else if len(disks) == 1 {
if capacityBytes != disks[0].Disk.CapacityGiB*1024*1024*1024 {
if capacityBytes != disks[0].Disk.CapacityGiB*util.GiB {
return nil, ErrDiskExistsDiffSize
}
return disks[0].Disk, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (m *metadata) GetInstanceID() string {
return m.instanceID
}

// GetRegion returns the region Zone which the instance is in.
// GetRegion returns the region which the instance is in.
func (m *metadata) GetRegion() string {
return m.region
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func TestCreateVolume(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), NewFakeMounter())
awsDriver := NewFakeDriver("", cloud.NewFakeCloudProvider(), NewFakeMounter())

resp, err := awsDriver.CreateVolume(context.TODO(), tc.req)
if err != nil {
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestDeleteVolume(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), NewFakeMounter())
awsDriver := NewFakeDriver("", cloud.NewFakeCloudProvider(), NewFakeMounter())
_, err := awsDriver.DeleteVolume(context.TODO(), tc.req)
if err != nil {
srvErr, ok := status.FromError(err)
Expand Down Expand Up @@ -499,7 +499,7 @@ func TestCreateSnapshot(t *testing.T) {
}
for _, tc := range testCases {
t.Logf("Test case: %s", tc.name)
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), NewFakeMounter())
awsDriver := NewFakeDriver("", cloud.NewFakeCloudProvider(), NewFakeMounter())
resp, err := awsDriver.CreateSnapshot(context.TODO(), tc.req)
if err != nil {
srvErr, ok := status.FromError(err)
Expand Down Expand Up @@ -565,7 +565,7 @@ func TestDeleteSnapshot(t *testing.T) {
}
for _, tc := range testCases {
t.Logf("Test case: %s", tc.name)
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), NewFakeMounter())
awsDriver := NewFakeDriver("", cloud.NewFakeCloudProvider(), NewFakeMounter())
snapResp, err := awsDriver.CreateSnapshot(context.TODO(), snapReq)
if err != nil {
t.Fatalf("Error creating testing snapshot: %v", err)
Expand All @@ -591,7 +591,7 @@ func TestDeleteSnapshot(t *testing.T) {
}

func TestControllerPublishVolume(t *testing.T) {
fakeCloud := NewFakeCloudProvider()
fakeCloud := cloud.NewFakeCloudProvider()
stdVolCap := &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{},
Expand Down Expand Up @@ -727,7 +727,7 @@ func TestControllerPublishVolume(t *testing.T) {
}

func TestControllerUnpublishVolume(t *testing.T) {
fakeCloud := NewFakeCloudProvider()
fakeCloud := cloud.NewFakeCloudProvider()
testCases := []struct {
name string
req *csi.ControllerUnpublishVolumeRequest
Expand Down
4 changes: 0 additions & 4 deletions pkg/driver/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
)

func NewFakeCloudProvider() *cloud.FakeCloudProvider {
return cloud.NewFakeCloudProvider()
}

func NewFakeMounter() *mount.FakeMounter {
return &mount.FakeMounter{
MountPoints: []mount.MountPoint{},
Expand Down
15 changes: 8 additions & 7 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/kubernetes/pkg/util/mount"
Expand Down Expand Up @@ -205,7 +206,7 @@ func TestNodeStageVolume(t *testing.T) {
if tc.fakeMountPoint != nil {
fakeMounter.MountPoints = append(fakeMounter.MountPoints, *tc.fakeMountPoint)
}
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), fakeMounter)
awsDriver := NewFakeDriver("", cloud.NewFakeCloudProvider(), fakeMounter)

_, err := awsDriver.NodeStageVolume(context.TODO(), tc.req)
if err != nil {
Expand Down Expand Up @@ -305,7 +306,7 @@ func TestNodeUnstageVolume(t *testing.T) {
if len(tc.fakeMountPoints) > 0 {
fakeMounter.MountPoints = tc.fakeMountPoints
}
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), fakeMounter)
awsDriver := NewFakeDriver("", cloud.NewFakeCloudProvider(), fakeMounter)

_, err := awsDriver.NodeUnstageVolume(context.TODO(), tc.req)
if err != nil {
Expand Down Expand Up @@ -535,7 +536,7 @@ func TestNodePublishVolume(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fakeMounter := NewFakeMounter()
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), fakeMounter)
awsDriver := NewFakeDriver("", cloud.NewFakeCloudProvider(), fakeMounter)

_, err := awsDriver.NodePublishVolume(context.TODO(), tc.req)
if err != nil {
Expand Down Expand Up @@ -612,7 +613,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
if tc.fakeMountPoint != nil {
fakeMounter.MountPoints = append(fakeMounter.MountPoints, *tc.fakeMountPoint)
}
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), fakeMounter)
awsDriver := NewFakeDriver("", cloud.NewFakeCloudProvider(), fakeMounter)

_, err := awsDriver.NodeUnpublishVolume(context.TODO(), tc.req)
if err != nil {
Expand All @@ -638,7 +639,7 @@ func TestNodeUnpublishVolume(t *testing.T) {

func TestNodeGetVolumeStats(t *testing.T) {
req := &csi.NodeGetVolumeStatsRequest{}
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), NewFakeMounter())
awsDriver := NewFakeDriver("", cloud.NewFakeCloudProvider(), NewFakeMounter())
expErrCode := codes.Unimplemented

_, err := awsDriver.NodeGetVolumeStats(context.TODO(), req)
Expand All @@ -656,7 +657,7 @@ func TestNodeGetVolumeStats(t *testing.T) {

func TestNodeGetCapabilities(t *testing.T) {
req := &csi.NodeGetCapabilitiesRequest{}
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), NewFakeMounter())
awsDriver := NewFakeDriver("", cloud.NewFakeCloudProvider(), NewFakeMounter())
caps := []*csi.NodeServiceCapability{
{
Type: &csi.NodeServiceCapability_Rpc{
Expand All @@ -683,7 +684,7 @@ func TestNodeGetCapabilities(t *testing.T) {

func TestNodeGetInfo(t *testing.T) {
req := &csi.NodeGetInfoRequest{}
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), NewFakeMounter())
awsDriver := NewFakeDriver("", cloud.NewFakeCloudProvider(), NewFakeMounter())
m := awsDriver.cloud.GetMetadata()
expResp := &csi.NodeGetInfoResponse{
NodeId: "instanceID",
Expand Down
3 changes: 2 additions & 1 deletion tests/sanity/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

sanity "github.com/kubernetes-csi/csi-test/pkg/sanity"

"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver"
)

Expand All @@ -43,7 +44,7 @@ func TestSanity(t *testing.T) {
}

var _ = BeforeSuite(func() {
ebsDriver = driver.NewFakeDriver(endpoint, driver.NewFakeCloudProvider(), driver.NewFakeMounter())
ebsDriver = driver.NewFakeDriver(endpoint, cloud.NewFakeCloudProvider(), driver.NewFakeMounter())
go func() {
Expect(ebsDriver.Run()).NotTo(HaveOccurred())
}()
Expand Down

0 comments on commit 1722563

Please sign in to comment.