Skip to content

Commit

Permalink
added func to create recyclers for easier testing. fixed unit test w/…
Browse files Browse the repository at this point in the history
… recycler additions
  • Loading branch information
markturansky committed May 22, 2015
1 parent 9ad7ea3 commit 105f92d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/volume/host_path/host_path.go
Expand Up @@ -80,7 +80,7 @@ func (plugin *hostPathPlugin) NewRecycler(spec *volume.Spec) (volume.Recycler, e
return plugin.newRecyclerFunc(spec, plugin.host)
}

func newRecycler(spec *volume.Spec, host volume.VolumeHost)(volume.Recycler, error){
func newRecycler(spec *volume.Spec, host volume.VolumeHost) (volume.Recycler, error) {
if spec.VolumeSource.HostPath != nil {
return &hostPathRecycler{spec.VolumeSource.HostPath.Path, host}, nil
} else {
Expand Down Expand Up @@ -139,7 +139,7 @@ func (hp *hostPathRecycler) Recycle() error {
2. use host.client to save to API and watch it
3. if pod errors or times out, return error
if pod exits, return nil for success
*/
*/

return nil
}
4 changes: 2 additions & 2 deletions pkg/volume/host_path/host_path_test.go
Expand Up @@ -60,7 +60,7 @@ func TestRecycler(t *testing.T) {
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins([]volume.VolumePlugin{&hostPathPlugin{nil, newMockRecycler}}, volume.NewFakeVolumeHost("/tmp/fake", nil, nil))

spec := &volume.Spec{PersistentVolumeSource:api.PersistentVolumeSource{HostPath: &api.HostPathVolumeSource{Path: "/foo"}}}
spec := &volume.Spec{PersistentVolumeSource: api.PersistentVolumeSource{HostPath: &api.HostPathVolumeSource{Path: "/foo"}}}
plug, err := plugMgr.FindRecyclablePluginBySpec(spec)
if err != nil {
t.Errorf("Can't find the plugin by name")
Expand All @@ -72,7 +72,7 @@ func TestRecycler(t *testing.T) {
if recycler.GetPath() != spec.PersistentVolumeSource.HostPath.Path {
t.Errorf("Expected %s but got %s", spec.PersistentVolumeSource.HostPath.Path, recycler.GetPath())
}
if err := recycler.Recycle() ; err != nil {
if err := recycler.Recycle(); err != nil {
t.Errorf("Mock Recycler expected to return nil but got %s", err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/volume/nfs/nfs.go
Expand Up @@ -105,7 +105,7 @@ func (plugin *nfsPlugin) NewRecycler(spec *volume.Spec) (volume.Recycler, error)
return plugin.newRecyclerFunc(spec, plugin.host)
}

func newRecycler(spec *volume.Spec, host volume.VolumeHost)(volume.Recycler, error){
func newRecycler(spec *volume.Spec, host volume.VolumeHost) (volume.Recycler, error) {
if spec.VolumeSource.HostPath != nil {
return &nfsRecycler{
volName: spec.Name,
Expand Down Expand Up @@ -225,7 +225,7 @@ type nfsRecycler struct {
volName string
server string
exportPath string
host volume.VolumeHost
host volume.VolumeHost
}

func (r *nfsRecycler) GetPath() string {
Expand All @@ -242,7 +242,7 @@ func (r *nfsRecycler) Recycle() error {
2. use host.client to save to API and watch it
3. if pod errors or times out, return error
if pod exits, return nil for success
*/
*/

return nil
}
6 changes: 2 additions & 4 deletions pkg/volume/nfs/nfs_test.go
Expand Up @@ -57,12 +57,11 @@ func TestGetAccessModes(t *testing.T) {
}
}


func TestRecycler(t *testing.T) {
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins([]volume.VolumePlugin{&nfsPlugin{newRecyclerFunc: newMockRecycler}}, volume.NewFakeVolumeHost("/tmp/fake", nil, nil))

spec := &volume.Spec{PersistentVolumeSource:api.PersistentVolumeSource{NFS: &api.NFSVolumeSource{Path: "/foo"}}}
spec := &volume.Spec{PersistentVolumeSource: api.PersistentVolumeSource{NFS: &api.NFSVolumeSource{Path: "/foo"}}}
plug, err := plugMgr.FindRecyclablePluginBySpec(spec)
if err != nil {
t.Errorf("Can't find the plugin by name")
Expand All @@ -74,7 +73,7 @@ func TestRecycler(t *testing.T) {
if recycler.GetPath() != spec.PersistentVolumeSource.NFS.Path {
t.Errorf("Expected %s but got %s", spec.PersistentVolumeSource.NFS.Path, recycler.GetPath())
}
if err := recycler.Recycle() ; err != nil {
if err := recycler.Recycle(); err != nil {
t.Errorf("Mock Recycler expected to return nil but got %s", err)
}
}
Expand All @@ -99,7 +98,6 @@ func (r *mockRecycler) Recycle() error {
return nil
}


func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeAccessMode) bool {
for _, m := range modes {
if m == mode {
Expand Down
1 change: 0 additions & 1 deletion pkg/volume/util.go
Expand Up @@ -59,7 +59,6 @@ func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeA

// basicVolumeScrubber is an implementation of volume.Recycler
type basicVolumeScrubber struct {

}

// podWatch provides watch semantics for a pod backed by a poller, since
Expand Down
2 changes: 2 additions & 0 deletions pkg/volumeclaimbinder/persistent_volume_claim_binder_test.go
Expand Up @@ -260,6 +260,8 @@ func TestBindingWithExamples(t *testing.T) {

// after the status change above, the binder picks up again
syncVolume(volumeIndex, mockClient, pv)
// the first change of the volume in the binder triggers another change
syncVolume(volumeIndex, mockClient, pv)

if pv.Status.Phase != api.VolumePending {
t.Errorf("Expected phase %s but got %s", api.VolumePending, pv.Status.Phase)
Expand Down

0 comments on commit 105f92d

Please sign in to comment.