mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
improved recycler unit test
This commit is contained in:
parent
616ba4ea9a
commit
a5feac5739
@ -63,7 +63,8 @@ func TestGetAccessModes(t *testing.T) {
|
|||||||
|
|
||||||
func TestRecycler(t *testing.T) {
|
func TestRecycler(t *testing.T) {
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins([]volume.VolumePlugin{&hostPathPlugin{nil, newMockRecycler}}, volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
volumeHost := volume.NewFakeVolumeHost("/tmp/fake", nil, nil)
|
||||||
|
plugMgr.InitPlugins([]volume.VolumePlugin{&hostPathPlugin{nil, volume.NewFakeRecycler}}, volumeHost)
|
||||||
|
|
||||||
spec := &volume.Spec{PersistentVolume: &api.PersistentVolume{Spec: api.PersistentVolumeSpec{PersistentVolumeSource: api.PersistentVolumeSource{HostPath: &api.HostPathVolumeSource{Path: "/foo"}}}}}
|
spec := &volume.Spec{PersistentVolume: &api.PersistentVolume{Spec: api.PersistentVolumeSpec{PersistentVolumeSource: api.PersistentVolumeSource{HostPath: &api.HostPathVolumeSource{Path: "/foo"}}}}}
|
||||||
plug, err := plugMgr.FindRecyclablePluginBySpec(spec)
|
plug, err := plugMgr.FindRecyclablePluginBySpec(spec)
|
||||||
@ -82,26 +83,6 @@ func TestRecycler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMockRecycler(spec *volume.Spec, host volume.VolumeHost) (volume.Recycler, error) {
|
|
||||||
return &mockRecycler{
|
|
||||||
path: spec.PersistentVolume.Spec.HostPath.Path,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type mockRecycler struct {
|
|
||||||
path string
|
|
||||||
host volume.VolumeHost
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *mockRecycler) GetPath() string {
|
|
||||||
return r.path
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *mockRecycler) Recycle() error {
|
|
||||||
// return nil means recycle passed
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPlugin(t *testing.T) {
|
func TestPlugin(t *testing.T) {
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost("fake", nil, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost("fake", nil, nil))
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package volume
|
package volume
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
@ -125,7 +126,7 @@ func (plugin *FakeVolumePlugin) NewCleaner(volName string, podUID types.UID, mou
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *FakeVolumePlugin) NewRecycler(spec *Spec) (Recycler, error) {
|
func (plugin *FakeVolumePlugin) NewRecycler(spec *Spec) (Recycler, error) {
|
||||||
return &FakeRecycler{"/attributesTransferredFromSpec"}, nil
|
return &fakeRecycler{"/attributesTransferredFromSpec"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *FakeVolumePlugin) GetAccessModes() []api.PersistentVolumeAccessMode {
|
func (plugin *FakeVolumePlugin) GetAccessModes() []api.PersistentVolumeAccessMode {
|
||||||
@ -162,15 +163,24 @@ func (fv *FakeVolume) TearDownAt(dir string) error {
|
|||||||
return os.RemoveAll(dir)
|
return os.RemoveAll(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
type FakeRecycler struct {
|
type fakeRecycler struct {
|
||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fr *FakeRecycler) Recycle() error {
|
func (fr *fakeRecycler) Recycle() error {
|
||||||
// nil is success, else error
|
// nil is success, else error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fr *FakeRecycler) GetPath() string {
|
func (fr *fakeRecycler) GetPath() string {
|
||||||
return fr.path
|
return fr.path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewFakeRecycler(spec *Spec, host VolumeHost) (Recycler, error) {
|
||||||
|
if spec.PersistentVolume == nil || spec.PersistentVolume.Spec.HostPath == nil {
|
||||||
|
return nil, fmt.Errorf("fakeRecycler only supports spec.PersistentVolume.Spec.HostPath")
|
||||||
|
}
|
||||||
|
return &fakeRecycler{
|
||||||
|
path: spec.PersistentVolume.Spec.HostPath.Path,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user