From 6a4b671a6453d3ecbbf1c5e0337a2594c3b3d0b8 Mon Sep 17 00:00:00 2001 From: NickrenREN Date: Fri, 18 Nov 2016 22:44:41 +0800 Subject: [PATCH] volume pluginsmgr functions test add function to test vpm functions in pkg/volume/plugins_test.go --- pkg/volume/BUILD | 1 + pkg/volume/plugins_test.go | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/pkg/volume/BUILD b/pkg/volume/BUILD index 8cd8487064f..b193d4eaa39 100644 --- a/pkg/volume/BUILD +++ b/pkg/volume/BUILD @@ -61,6 +61,7 @@ go_test( "//pkg/api/errors:go_default_library", "//pkg/api/resource:go_default_library", "//pkg/api/v1:go_default_library", + "//pkg/types:go_default_library", "//pkg/util/testing:go_default_library", "//pkg/watch:go_default_library", ], diff --git a/pkg/volume/plugins_test.go b/pkg/volume/plugins_test.go index 3523b74c93d..7eaf2840afa 100644 --- a/pkg/volume/plugins_test.go +++ b/pkg/volume/plugins_test.go @@ -20,6 +20,7 @@ import ( "testing" "k8s.io/kubernetes/pkg/api/v1" + "k8s.io/kubernetes/pkg/types" ) func TestSpecSourceConverters(t *testing.T) { @@ -51,3 +52,55 @@ func TestSpecSourceConverters(t *testing.T) { t.Errorf("Expected %v but got %v", pv.Name, converted.Name()) } } + +type testPlugins struct { +} + +func (plugin *testPlugins) Init(host VolumeHost) error { + return nil +} + +func (plugin *testPlugins) GetPluginName() string { + return "testPlugin" +} + +func (plugin *testPlugins) GetVolumeName(spec *Spec) (string, error) { + return "", nil +} + +func (plugin *testPlugins) CanSupport(spec *Spec) bool { + return true +} + +func (plugin *testPlugins) RequiresRemount() bool { + return false +} + +func (plugin *testPlugins) NewMounter(spec *Spec, podRef *v1.Pod, opts VolumeOptions) (Mounter, error) { + return nil, nil +} + +func (plugin *testPlugins) NewUnmounter(name string, podUID types.UID) (Unmounter, error) { + return nil, nil +} + +func (plugin *testPlugins) ConstructVolumeSpec(volumeName, mountPath string) (*Spec, error) { + return nil, nil +} + +func newTestPlugin() []VolumePlugin { + return []VolumePlugin{&testPlugins{}} +} + +func TestVolumePluginMgrFunc(t *testing.T) { + vpm := VolumePluginMgr{} + vpm.InitPlugins(newTestPlugin(), nil) + + plug, err := vpm.FindPluginByName("testPlugin") + if err != nil { + t.Errorf("Can't find the plugin by name") + } + if plug.GetPluginName() != "testPlugin" { + t.Errorf("Wrong name: %s", plug.GetPluginName()) + } +}