test: using ioutil.TempDir in unit tests per #15176

update

update mode

delete /tmp

update

use ioutil.TempDir instead of static tmp dir

use ioutil.TempDir instead of static tmp dir
This commit is contained in:
jijun2
2015-10-12 20:28:03 +08:00
parent 4264aac1e9
commit bf6e8cbff7
8 changed files with 189 additions and 49 deletions

View File

@@ -17,7 +17,9 @@ limitations under the License.
package cinder
import (
"io/ioutil"
"os"
"path"
"testing"
"k8s.io/kubernetes/pkg/api"
@@ -27,8 +29,13 @@ import (
)
func TestCanSupport(t *testing.T) {
tmpDir, err := ioutil.TempDir(os.TempDir(), "cinderTest")
if err != nil {
t.Fatalf("can't make a temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/cinder")
if err != nil {
@@ -67,8 +74,13 @@ func (fake *fakePDManager) DetachDisk(c *cinderVolumeCleaner) error {
}
func TestPlugin(t *testing.T) {
tmpDir, err := ioutil.TempDir(os.TempDir(), "cinderTest")
if err != nil {
t.Fatalf("can't make a temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
plug, err := plugMgr.FindPluginByName("kubernetes.io/cinder")
if err != nil {
@@ -90,9 +102,9 @@ func TestPlugin(t *testing.T) {
if builder == nil {
t.Errorf("Got a nil Builder: %v")
}
volPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~cinder/vol1")
path := builder.GetPath()
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~cinder/vol1" {
if path != volPath {
t.Errorf("Got unexpected path: %s", path)
}