volume pluginsmgr functions test

add function to test vpm functions in pkg/volume/plugins_test.go
This commit is contained in:
NickrenREN 2016-11-18 22:44:41 +08:00
parent 69170e7243
commit 6a4b671a64
2 changed files with 54 additions and 0 deletions

View File

@ -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",
],

View File

@ -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())
}
}