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
f614e7df
Commit
f614e7df
authored
Sep 22, 2015
by
Eric Tune
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14168 from tmrts/refactor/tests
Refactor downward API volume plugin test
parents
6dbb7810
c01bac90
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
17 deletions
+24
-17
downwardapi_test.go
pkg/volume/downwardapi/downwardapi_test.go
+24
-17
No files found.
pkg/volume/downwardapi/downwardapi_test.go
View file @
f614e7df
...
@@ -600,7 +600,8 @@ func TestWriteWithUnixPathBadPath(t *testing.T) {
...
@@ -600,7 +600,8 @@ func TestWriteWithUnixPathBadPath(t *testing.T) {
labels
:=
map
[
string
]
string
{
labels
:=
map
[
string
]
string
{
"key1"
:
"value1"
,
"key1"
:
"value1"
,
"key2"
:
"value2"
}
"key2"
:
"value2"
,
}
fake
:=
testclient
.
NewSimpleFake
(
&
api
.
Pod
{
fake
:=
testclient
.
NewSimpleFake
(
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
...
@@ -613,42 +614,48 @@ func TestWriteWithUnixPathBadPath(t *testing.T) {
...
@@ -613,42 +614,48 @@ func TestWriteWithUnixPathBadPath(t *testing.T) {
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
:=
volume
.
VolumePluginMgr
{}
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
))
pluginMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
,
fake
))
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
plugin
,
err
:=
pluginMgr
.
FindPluginByName
(
downwardAPIPluginName
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
}
volumeSpec
:=
&
api
.
Volume
{
volumeSpec
:=
&
api
.
Volume
{
Name
:
testVolumeName
,
Name
:
testVolumeName
,
VolumeSource
:
api
.
VolumeSource
{
VolumeSource
:
api
.
VolumeSource
{
DownwardAPI
:
&
api
.
DownwardAPIVolumeSource
{
DownwardAPI
:
&
api
.
DownwardAPIVolumeSource
{
Items
:
[]
api
.
DownwardAPIVolumeFile
{
Items
:
[]
api
.
DownwardAPIVolumeFile
{
{
Path
:
"this//labels"
,
FieldRef
:
api
.
ObjectFieldSelector
{
{
FieldPath
:
"metadata.labels"
}},
Path
:
"this//labels"
,
}}},
FieldRef
:
api
.
ObjectFieldSelector
{
}
FieldPath
:
"metadata.labels"
,
if
err
!=
nil
{
},
t
.
Errorf
(
"Can't find the plugin by name"
)
},
},
},
},
}
}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
testPodUID
,
Labels
:
labels
}}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
testPodUID
,
Labels
:
labels
}}
builder
,
err
:=
plugin
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
volumeSpec
),
pod
,
volume
.
VolumeOptions
{})
builder
,
err
:=
plugin
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
volumeSpec
),
pod
,
volume
.
VolumeOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Builder: %v"
,
err
)
t
.
Fatalf
(
"Failed to make a new Builder: %v"
,
err
)
}
}
else
if
builder
==
nil
{
if
builder
==
nil
{
t
.
Fatalf
(
"Got a nil Builder"
)
t
.
Errorf
(
"Got a nil Builder"
)
}
}
volumePath
:=
builder
.
GetPath
()
volumePath
:=
builder
.
GetPath
()
defer
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
err
=
builder
.
SetUp
()
err
=
builder
.
SetUp
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
f
(
"Failed to setup volume: %v"
,
err
)
t
.
Fatal
f
(
"Failed to setup volume: %v"
,
err
)
}
}
var
data
[]
byte
data
,
err
:=
ioutil
.
ReadFile
(
path
.
Join
(
volumePath
,
"this/labels"
))
data
,
err
=
ioutil
.
ReadFile
(
path
.
Join
(
volumePath
,
"this/labels"
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
f
(
err
.
Error
())
t
.
Fatal
f
(
err
.
Error
())
}
}
if
sortLines
(
string
(
data
))
!=
sortLines
(
formatMap
(
labels
))
{
if
sortLines
(
string
(
data
))
!=
sortLines
(
formatMap
(
labels
))
{
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
formatMap
(
labels
))
t
.
Errorf
(
"Found `%s` expected %s"
,
data
,
formatMap
(
labels
))
}
}
CleanEverything
(
plugin
,
testVolumeName
,
volumePath
,
testPodUID
,
t
)
}
}
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