本文整理匯總了Golang中k8s/io/kubernetes/pkg/volume.VolumePluginMgr.FindDeletablePluginBySpec方法的典型用法代碼示例。如果您正苦於以下問題:Golang VolumePluginMgr.FindDeletablePluginBySpec方法的具體用法?Golang VolumePluginMgr.FindDeletablePluginBySpec怎麽用?Golang VolumePluginMgr.FindDeletablePluginBySpec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/volume.VolumePluginMgr
的用法示例。
在下文中一共展示了VolumePluginMgr.FindDeletablePluginBySpec方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestDeleter
func TestDeleter(t *testing.T) {
tempPath := fmt.Sprintf("/tmp/hostpath/%s", util.NewUUID())
defer os.RemoveAll(tempPath)
err := os.MkdirAll(tempPath, 0750)
if err != nil {
t.Fatalf("Failed to create tmp directory for deleter: %v", err)
}
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
spec := &volume.Spec{PersistentVolume: &api.PersistentVolume{Spec: api.PersistentVolumeSpec{PersistentVolumeSource: api.PersistentVolumeSource{HostPath: &api.HostPathVolumeSource{Path: tempPath}}}}}
plug, err := plugMgr.FindDeletablePluginBySpec(spec)
if err != nil {
t.Errorf("Can't find the plugin by name")
}
deleter, err := plug.NewDeleter(spec)
if err != nil {
t.Errorf("Failed to make a new Deleter: %v", err)
}
if deleter.GetPath() != tempPath {
t.Errorf("Expected %s but got %s", tempPath, deleter.GetPath())
}
if err := deleter.Delete(); err != nil {
t.Errorf("Mock Recycler expected to return nil but got %s", err)
}
if exists, _ := util.FileExists("foo"); exists {
t.Errorf("Temp path expected to be deleted, but was found at %s", tempPath)
}
}
示例2: TestDeleterTempDir
func TestDeleterTempDir(t *testing.T) {
tests := map[string]struct {
expectedFailure bool
path string
}{
"just-tmp": {true, "/tmp"},
"not-tmp": {true, "/nottmp"},
"good-tmp": {false, "/tmp/scratch"},
}
for name, test := range tests {
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
spec := &volume.Spec{PersistentVolume: &api.PersistentVolume{Spec: api.PersistentVolumeSpec{PersistentVolumeSource: api.PersistentVolumeSource{HostPath: &api.HostPathVolumeSource{Path: test.path}}}}}
plug, _ := plugMgr.FindDeletablePluginBySpec(spec)
deleter, _ := plug.NewDeleter(spec)
err := deleter.Delete()
if err == nil && test.expectedFailure {
t.Errorf("Expected failure for test '%s' but got nil err", name)
}
if err != nil && !test.expectedFailure {
t.Errorf("Unexpected failure for test '%s': %v", name, err)
}
}
}