From 2c9e84f50f1191b646481cf6270ab99a372df91e Mon Sep 17 00:00:00 2001
From: guangxuli
Date: Sat, 8 Oct 2016 16:58:56 +0800
Subject: [PATCH] add a clean code for TestCanSupport
update other location
forgot two files need to be updated
---
pkg/volume/configmap/configmap_test.go | 15 +++++++++------
pkg/volume/git_repo/git_repo_test.go | 4 +++-
pkg/volume/secret/secret_test.go | 7 ++++---
3 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/pkg/volume/configmap/configmap_test.go b/pkg/volume/configmap/configmap_test.go
index 170f3093264..9fc9719a978 100644
--- a/pkg/volume/configmap/configmap_test.go
+++ b/pkg/volume/configmap/configmap_test.go
@@ -249,7 +249,8 @@ func newTestHost(t *testing.T, clientset clientset.Interface) (string, volume.Vo
func TestCanSupport(t *testing.T) {
pluginMgr := volume.VolumePluginMgr{}
- _, host := newTestHost(t, nil)
+ tempDir, host := newTestHost(t, nil)
+ defer os.RemoveAll(tempDir)
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
plugin, err := pluginMgr.FindPluginByName(configMapPluginName)
@@ -274,13 +275,14 @@ func TestPlugin(t *testing.T) {
testNamespace = "test_configmap_namespace"
testName = "test_configmap_name"
- volumeSpec = volumeSpec(testVolumeName, testName, 0644)
- configMap = configMap(testNamespace, testName)
- client = fake.NewSimpleClientset(&configMap)
- pluginMgr = volume.VolumePluginMgr{}
- _, host = newTestHost(t, client)
+ volumeSpec = volumeSpec(testVolumeName, testName, 0644)
+ configMap = configMap(testNamespace, testName)
+ client = fake.NewSimpleClientset(&configMap)
+ pluginMgr = volume.VolumePluginMgr{}
+ tempDir, host = newTestHost(t, client)
)
+ defer os.RemoveAll(tempDir)
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
plugin, err := pluginMgr.FindPluginByName(configMapPluginName)
@@ -344,6 +346,7 @@ func TestPluginReboot(t *testing.T) {
rootDir, host = newTestHost(t, client)
)
+ defer os.RemoveAll(rootDir)
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
plugin, err := pluginMgr.FindPluginByName(configMapPluginName)
diff --git a/pkg/volume/git_repo/git_repo_test.go b/pkg/volume/git_repo/git_repo_test.go
index 8ef0be9acb3..be3a767acbe 100644
--- a/pkg/volume/git_repo/git_repo_test.go
+++ b/pkg/volume/git_repo/git_repo_test.go
@@ -43,7 +43,8 @@ func newTestHost(t *testing.T) (string, volume.VolumeHost) {
func TestCanSupport(t *testing.T) {
plugMgr := volume.VolumePluginMgr{}
- _, host := newTestHost(t)
+ tempDir, host := newTestHost(t)
+ defer os.RemoveAll(tempDir)
plugMgr.InitPlugins(ProbeVolumePlugins(), host)
plug, err := plugMgr.FindPluginByName("kubernetes.io/git-repo")
@@ -221,6 +222,7 @@ func doTestPlugin(scenario struct {
plugMgr := volume.VolumePluginMgr{}
rootDir, host := newTestHost(t)
+ defer os.RemoveAll(rootDir)
plugMgr.InitPlugins(ProbeVolumePlugins(), host)
plug, err := plugMgr.FindPluginByName("kubernetes.io/git-repo")
diff --git a/pkg/volume/secret/secret_test.go b/pkg/volume/secret/secret_test.go
index da9276f2225..32029d6ba83 100644
--- a/pkg/volume/secret/secret_test.go
+++ b/pkg/volume/secret/secret_test.go
@@ -252,7 +252,8 @@ func newTestHost(t *testing.T, clientset clientset.Interface) (string, volume.Vo
func TestCanSupport(t *testing.T) {
pluginMgr := volume.VolumePluginMgr{}
- _, host := newTestHost(t, nil)
+ tempDir, host := newTestHost(t, nil)
+ defer os.RemoveAll(tempDir)
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
plugin, err := pluginMgr.FindPluginByName(secretPluginName)
@@ -283,7 +284,7 @@ func TestPlugin(t *testing.T) {
pluginMgr = volume.VolumePluginMgr{}
rootDir, host = newTestHost(t, client)
)
-
+ defer os.RemoveAll(rootDir)
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
plugin, err := pluginMgr.FindPluginByName(secretPluginName)
@@ -356,7 +357,7 @@ func TestPluginReboot(t *testing.T) {
pluginMgr = volume.VolumePluginMgr{}
rootDir, host = newTestHost(t, client)
)
-
+ defer os.RemoveAll(rootDir)
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
plugin, err := pluginMgr.FindPluginByName(secretPluginName)