Skip to content

Commit

Permalink
Add fake cloud provider parameter to NewFakeDriver.
Browse files Browse the repository at this point in the history
Signed-off-by: Simão Reis <[email protected]>
  • Loading branch information
Simão Reis committed Feb 19, 2019
1 parent b04d99a commit f65d49a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 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("", NewFakeMounter())
awsDriver := NewFakeDriver("", 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("", NewFakeMounter())
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), NewFakeMounter())
_, err := awsDriver.DeleteVolume(context.TODO(), tc.req)
if err != nil {
srvErr, ok := status.FromError(err)
Expand Down
11 changes: 7 additions & 4 deletions pkg/driver/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ 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 All @@ -38,12 +42,11 @@ func NewFakeSafeFormatAndMounter(fakeMounter *mount.FakeMounter) *mount.SafeForm
}

// NewFakeDriver creates a new mock driver used for testing
func NewFakeDriver(endpoint string, fakeMounter *mount.FakeMounter) *Driver {
cloud := cloud.NewFakeCloudProvider()
func NewFakeDriver(endpoint string, fakeCloud *cloud.FakeCloudProvider, fakeMounter *mount.FakeMounter) *Driver {
return &Driver{
endpoint: endpoint,
nodeID: cloud.GetMetadata().GetInstanceID(),
cloud: cloud,
nodeID: fakeCloud.GetMetadata().GetInstanceID(),
cloud: fakeCloud,
mounter: NewFakeSafeFormatAndMounter(fakeMounter),
inFlight: internal.NewInFlight(),
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func TestNodeStageVolume(t *testing.T) {
if tc.fakeMountPoint != nil {
fakeMounter.MountPoints = append(fakeMounter.MountPoints, *tc.fakeMountPoint)
}
awsDriver := NewFakeDriver("", fakeMounter)
awsDriver := NewFakeDriver("", NewFakeCloudProvider(), fakeMounter)

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

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

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

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

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

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

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

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

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

0 comments on commit f65d49a

Please sign in to comment.