Skip to content

Commit

Permalink
Merge pull request #187 from mesosphere/sreis/node-unit-tests
Browse files Browse the repository at this point in the history
Add unit tests for node service.
  • Loading branch information
k8s-ci-robot authored Jan 25, 2019
2 parents 2a5d5ff + c98c715 commit 2d4b4e5
Show file tree
Hide file tree
Showing 4 changed files with 636 additions and 11 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.Logf("Test case: %s", tc.name)
awsDriver := NewFakeDriver("")
awsDriver := NewFakeDriver("", 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.Logf("Test case: %s", tc.name)
awsDriver := NewFakeDriver("")
awsDriver := NewFakeDriver("", NewFakeMounter())
_, err := awsDriver.DeleteVolume(context.TODO(), tc.req)
if err != nil {
srvErr, ok := status.FromError(err)
Expand Down
20 changes: 12 additions & 8 deletions pkg/driver/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,29 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
)

func NewFakeMounter() *mount.SafeFormatAndMount {
func NewFakeMounter() *mount.FakeMounter {
return &mount.FakeMounter{
MountPoints: []mount.MountPoint{},
Log: []mount.FakeAction{},
}
}

func NewFakeSafeFormatAndMounter(fakeMounter *mount.FakeMounter) *mount.SafeFormatAndMount {
return &mount.SafeFormatAndMount{
Interface: &mount.FakeMounter{
MountPoints: []mount.MountPoint{},
Log: []mount.FakeAction{},
},
Exec: mount.NewFakeExec(nil),
Interface: fakeMounter,
Exec: mount.NewFakeExec(nil),
}

}

// NewFakeDriver creates a new mock driver used for testing
func NewFakeDriver(endpoint string) *Driver {
func NewFakeDriver(endpoint string, fakeMounter *mount.FakeMounter) *Driver {
cloud := cloud.NewFakeCloudProvider()
return &Driver{
endpoint: endpoint,
nodeID: cloud.GetMetadata().GetInstanceID(),
cloud: cloud,
mounter: NewFakeMounter(),
mounter: NewFakeSafeFormatAndMounter(fakeMounter),
inFlight: internal.NewInFlight(),
}
}
Loading

0 comments on commit 2d4b4e5

Please sign in to comment.