Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
bf6e8cbf
Commit
bf6e8cbf
authored
Oct 12, 2015
by
jijun2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
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
parent
4264aac1
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
189 additions
and
49 deletions
+189
-49
cni_test.go
pkg/kubelet/network/cni/cni_test.go
+16
-12
runonce_test.go
pkg/kubelet/runonce_test.go
+8
-2
aws_ebs_test.go
pkg/volume/aws_ebs/aws_ebs_test.go
+34
-7
cephfs_test.go
pkg/volume/cephfs/cephfs_test.go
+16
-3
cinder_test.go
pkg/volume/cinder/cinder_test.go
+16
-4
downwardapi_test.go
pkg/volume/downwardapi/downwardapi_test.go
+56
-12
empty_dir_test.go
pkg/volume/empty_dir/empty_dir_test.go
+15
-4
gce_pd_test.go
pkg/volume/gce_pd/gce_pd_test.go
+28
-5
No files found.
pkg/kubelet/network/cni/cni_test.go
View file @
bf6e8cbf
...
...
@@ -42,10 +42,15 @@ import (
)
// The temp dir where test plugins will be stored.
const
testNetworkConfigPath
=
"/tmp/fake/plugins/net/cni"
const
testVendorCNIDirPrefix
=
"/tmp"
func
tmpDirOrDie
()
string
{
dir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"cni-test"
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"error creating tmp dir: %v"
,
err
))
}
return
dir
}
func
installPluginUnderTest
(
t
*
testing
.
T
,
vendorName
string
,
plugName
string
)
{
func
installPluginUnderTest
(
t
*
testing
.
T
,
testVendorCNIDirPrefix
,
testNetworkConfigPath
,
vendorName
string
,
plugName
string
)
{
pluginDir
:=
path
.
Join
(
testNetworkConfigPath
,
plugName
)
err
:=
os
.
MkdirAll
(
pluginDir
,
0777
)
if
err
!=
nil
{
...
...
@@ -103,13 +108,8 @@ echo -n "{ \"ip4\": { \"ip\": \"10.1.0.23/24\" } }"
f
.
Close
()
}
func
tearDownPlugin
(
plugName
string
,
vendorName
string
)
{
err
:=
os
.
RemoveAll
(
testNetworkConfigPath
)
if
err
!=
nil
{
fmt
.
Printf
(
"Error in cleaning up test: %v"
,
err
)
}
vendorCNIDir
:=
fmt
.
Sprintf
(
VendorCNIDirTemplate
,
testVendorCNIDirPrefix
,
vendorName
)
err
=
os
.
RemoveAll
(
vendorCNIDir
)
func
tearDownPlugin
(
tmpDir
string
)
{
err
:=
os
.
RemoveAll
(
tmpDir
)
if
err
!=
nil
{
fmt
.
Printf
(
"Error in cleaning up test: %v"
,
err
)
}
...
...
@@ -167,8 +167,12 @@ func TestCNIPlugin(t *testing.T) {
// install some random plugin
pluginName
:=
fmt
.
Sprintf
(
"test%d"
,
rand
.
Intn
(
1000
))
vendorName
:=
fmt
.
Sprintf
(
"test_vendor%d"
,
rand
.
Intn
(
1000
))
defer
tearDownPlugin
(
pluginName
,
vendorName
)
installPluginUnderTest
(
t
,
vendorName
,
pluginName
)
tmpDir
:=
tmpDirOrDie
()
testNetworkConfigPath
:=
path
.
Join
(
tmpDir
,
"plugins"
,
"net"
,
"cni"
)
testVendorCNIDirPrefix
:=
tmpDir
defer
tearDownPlugin
(
tmpDir
)
installPluginUnderTest
(
t
,
testVendorCNIDirPrefix
,
testNetworkConfigPath
,
vendorName
,
pluginName
)
np
:=
probeNetworkPluginsWithVendorCNIDirPrefix
(
path
.
Join
(
testNetworkConfigPath
,
pluginName
),
testVendorCNIDirPrefix
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
np
,
"cni"
,
NewFakeHost
(
nil
))
...
...
pkg/kubelet/runonce_test.go
View file @
bf6e8cbf
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
kubelet
import
(
"io/ioutil"
"os"
"testing"
"time"
...
...
@@ -36,9 +38,13 @@ func TestRunOnce(t *testing.T) {
podManager
:=
kubepod
.
NewBasicPodManager
(
kubepod
.
NewFakeMirrorClient
())
diskSpaceManager
,
_
:=
newDiskSpaceManager
(
cadvisor
,
DiskSpacePolicy
{})
fakeRuntime
:=
&
kubecontainer
.
FakeRuntime
{}
basePath
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"kubelet"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp rootdir %v"
,
err
)
}
defer
os
.
RemoveAll
(
basePath
)
kb
:=
&
Kubelet
{
rootDirectory
:
"/tmp/kubelet"
,
rootDirectory
:
basePath
,
recorder
:
&
record
.
FakeRecorder
{},
cadvisor
:
cadvisor
,
nodeLister
:
testNodeLister
{},
...
...
pkg/volume/aws_ebs/aws_ebs_test.go
View file @
bf6e8cbf
...
...
@@ -17,7 +17,9 @@ limitations under the License.
package
aws_ebs
import
(
"io/ioutil"
"os"
"path"
"testing"
"k8s.io/kubernetes/pkg/api"
...
...
@@ -29,8 +31,13 @@ import (
)
func
TestCanSupport
(
t
*
testing
.
T
)
{
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"awsebsTest"
)
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/aws-ebs"
)
if
err
!=
nil
{
...
...
@@ -48,8 +55,13 @@ func TestCanSupport(t *testing.T) {
}
func
TestGetAccessModes
(
t
*
testing
.
T
)
{
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"awsebsTest"
)
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
.
FindPersistentPluginByName
(
"kubernetes.io/aws-ebs"
)
if
err
!=
nil
{
...
...
@@ -95,8 +107,13 @@ func (fake *fakePDManager) DetachDisk(c *awsElasticBlockStoreCleaner) error {
}
func
TestPlugin
(
t
*
testing
.
T
)
{
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"awsebsTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
)
}
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/aws-ebs"
)
if
err
!=
nil
{
...
...
@@ -118,9 +135,9 @@ func TestPlugin(t *testing.T) {
if
builder
==
nil
{
t
.
Errorf
(
"Got a nil Builder"
)
}
volPath
:=
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~aws-ebs/vol1"
)
path
:=
builder
.
GetPath
()
if
path
!=
"/tmp/fake/pods/poduid/volumes/kubernetes.io~aws-ebs/vol1"
{
if
path
!=
volPath
{
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
}
...
...
@@ -194,8 +211,13 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
client
:=
&
testclient
.
Fake
{}
client
.
AddReactor
(
"*"
,
"*"
,
testclient
.
ObjectReaction
(
o
,
testapi
.
Default
.
RESTMapper
()))
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"awsebsTest"
)
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"
,
client
,
nil
))
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
tmpDir
,
client
,
nil
))
plug
,
_
:=
plugMgr
.
FindPluginByName
(
awsElasticBlockStorePluginName
)
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
...
...
@@ -209,8 +231,13 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
}
func
TestBuilderAndCleanerTypeAssert
(
t
*
testing
.
T
)
{
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"awsebsTest"
)
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/aws-ebs"
)
if
err
!=
nil
{
...
...
pkg/volume/cephfs/cephfs_test.go
View file @
bf6e8cbf
...
...
@@ -17,7 +17,9 @@ limitations under the License.
package
cephfs
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
(),
"cephTest"
)
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
(
"fake"
,
nil
,
nil
))
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
tmpDir
,
nil
,
nil
))
plug
,
err
:=
plugMgr
.
FindPluginByName
(
"kubernetes.io/cephfs"
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
...
...
@@ -45,8 +52,13 @@ func TestCanSupport(t *testing.T) {
}
func
TestPlugin
(
t
*
testing
.
T
)
{
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"cephTest"
)
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/cephfs"
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
...
...
@@ -71,8 +83,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~cephfs/vol1"
)
path
:=
builder
.
GetPath
()
if
path
!=
"/tmp/fake/pods/poduid/volumes/kubernetes.io~cephfs/vol1"
{
if
path
!=
volpath
{
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
}
if
err
:=
builder
.
SetUp
();
err
!=
nil
{
...
...
pkg/volume/cinder/cinder_test.go
View file @
bf6e8cbf
...
...
@@ -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
)
}
...
...
pkg/volume/downwardapi/downwardapi_test.go
View file @
bf6e8cbf
...
...
@@ -31,8 +31,6 @@ import (
"k8s.io/kubernetes/pkg/volume/empty_dir"
)
const
basePath
=
"/tmp/fake"
func
formatMap
(
m
map
[
string
]
string
)
(
fmtstr
string
)
{
for
key
,
value
:=
range
m
{
fmtstr
+=
fmt
.
Sprintf
(
"%v=%q
\n
"
,
key
,
value
)
...
...
@@ -41,7 +39,7 @@ func formatMap(m map[string]string) (fmtstr string) {
return
}
func
newTestHost
(
t
*
testing
.
T
,
client
client
.
Interface
)
volume
.
VolumeHost
{
func
newTestHost
(
t
*
testing
.
T
,
client
client
.
Interface
,
basePath
string
)
volume
.
VolumeHost
{
tempDir
,
err
:=
ioutil
.
TempDir
(
basePath
,
"downwardApi_volume_test."
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp rootdir: %v"
,
err
)
...
...
@@ -50,8 +48,13 @@ func newTestHost(t *testing.T, client client.Interface) volume.VolumeHost {
}
func
TestCanSupport
(
t
*
testing
.
T
)
{
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"downwardapiTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
nil
))
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
nil
,
tmpDir
))
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
if
err
!=
nil
{
...
...
@@ -100,8 +103,14 @@ func TestLabels(t *testing.T) {
Labels
:
labels
,
},
})
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"downwardapiTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
))
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
volumeSpec
:=
&
api
.
Volume
{
Name
:
testVolumeName
,
...
...
@@ -174,8 +183,13 @@ func TestAnnotations(t *testing.T) {
},
})
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"downwardapiTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
))
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
...
...
@@ -234,8 +248,13 @@ func TestName(t *testing.T) {
},
})
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"downwardapiTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
))
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
...
...
@@ -295,8 +314,13 @@ func TestNamespace(t *testing.T) {
},
})
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"downwardapiTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
))
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
...
...
@@ -349,8 +373,13 @@ func TestWriteTwiceNoUpdate(t *testing.T) {
Labels
:
labels
,
},
})
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"downwardapiTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
))
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
volumeSpec
:=
&
api
.
Volume
{
Name
:
testVolumeName
,
...
...
@@ -433,8 +462,13 @@ func TestWriteTwiceWithUpdate(t *testing.T) {
Labels
:
labels
,
},
})
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"downwardapiTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
))
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
volumeSpec
:=
&
api
.
Volume
{
Name
:
testVolumeName
,
...
...
@@ -537,8 +571,13 @@ func TestWriteWithUnixPath(t *testing.T) {
},
})
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"downwardapiTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
))
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
volumeSpec
:=
&
api
.
Volume
{
Name
:
testVolumeName
,
...
...
@@ -611,8 +650,13 @@ func TestWriteWithUnixPathBadPath(t *testing.T) {
},
})
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"downwardapiTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir"
)
}
defer
os
.
RemoveAll
(
tmpDir
)
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
))
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
,
tmpDir
))
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
...
...
pkg/volume/empty_dir/empty_dir_test.go
View file @
bf6e8cbf
...
...
@@ -42,7 +42,12 @@ func makePluginUnderTest(t *testing.T, plugName, basePath string) volume.VolumeP
}
func
TestCanSupport
(
t
*
testing
.
T
)
{
plug
:=
makePluginUnderTest
(
t
,
"kubernetes.io/empty-dir"
,
"/tmp/fake"
)
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"emptydirTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tmpDir
)
plug
:=
makePluginUnderTest
(
t
,
"kubernetes.io/empty-dir"
,
tmpDir
)
if
plug
.
Name
()
!=
"kubernetes.io/empty-dir"
{
t
.
Errorf
(
"Wrong name: %s"
,
plug
.
Name
())
...
...
@@ -135,10 +140,11 @@ type pluginTestConfig struct {
// doTestPlugin sets up a volume and tears it back down.
func
doTestPlugin
(
t
*
testing
.
T
,
config
pluginTestConfig
)
{
basePath
,
err
:=
ioutil
.
TempDir
(
"/tmp"
,
"emptydir_volume_test"
)
basePath
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
()
,
"emptydir_volume_test"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp rootdir
"
)
t
.
Fatalf
(
"can't make a temp rootdir
: %v"
,
err
)
}
defer
os
.
RemoveAll
(
basePath
)
var
(
volumePath
=
path
.
Join
(
basePath
,
"pods/poduid/volumes/kubernetes.io~empty-dir/test-volume"
)
...
...
@@ -281,7 +287,12 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) {
}
func
TestPluginBackCompat
(
t
*
testing
.
T
)
{
basePath
:=
"/tmp/fake"
basePath
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"emptydirTest"
)
if
err
!=
nil
{
t
.
Fatalf
(
"can't make a temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
basePath
)
plug
:=
makePluginUnderTest
(
t
,
"kubernetes.io/empty-dir"
,
basePath
)
spec
:=
&
api
.
Volume
{
...
...
pkg/volume/gce_pd/gce_pd_test.go
View file @
bf6e8cbf
...
...
@@ -17,7 +17,9 @@ limitations under the License.
package
gce_pd
import
(
"io/ioutil"
"os"
"path"
"testing"
"k8s.io/kubernetes/pkg/api"
...
...
@@ -29,8 +31,13 @@ import (
)
func
TestCanSupport
(
t
*
testing
.
T
)
{
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"gcepdTest"
)
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/gce-pd"
)
if
err
!=
nil
{
...
...
@@ -48,8 +55,13 @@ func TestCanSupport(t *testing.T) {
}
func
TestGetAccessModes
(
t
*
testing
.
T
)
{
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"gcepdTest"
)
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
.
FindPersistentPluginByName
(
"kubernetes.io/gce-pd"
)
if
err
!=
nil
{
...
...
@@ -100,8 +112,13 @@ func (fake *fakePDManager) DetachDisk(c *gcePersistentDiskCleaner) error {
}
func
TestPlugin
(
t
*
testing
.
T
)
{
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"gcepdTest"
)
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/gce-pd"
)
if
err
!=
nil
{
...
...
@@ -126,8 +143,9 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"Got a nil Builder"
)
}
volPath
:=
path
.
Join
(
tmpDir
,
"pods/poduid/volumes/kubernetes.io~gce-pd/vol1"
)
path
:=
builder
.
GetPath
()
if
path
!=
"/tmp/fake/pods/poduid/volumes/kubernetes.io~gce-pd/vol1"
{
if
path
!=
volPath
{
t
.
Errorf
(
"Got unexpected path: %s"
,
path
)
}
...
...
@@ -208,8 +226,13 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
client
:=
&
testclient
.
Fake
{}
client
.
AddReactor
(
"*"
,
"*"
,
testclient
.
ObjectReaction
(
o
,
testapi
.
Default
.
RESTMapper
()))
tmpDir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"gcepdTest"
)
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"
,
client
,
nil
))
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
tmpDir
,
client
,
nil
))
plug
,
_
:=
plugMgr
.
FindPluginByName
(
gcePersistentDiskPluginName
)
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment