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
6ddc30c4
Commit
6ddc30c4
authored
Sep 09, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13648 from markturansky/voltesting_mockrecycler
Auto commit by PR queue bot
parents
c08ee667
a5feac57
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
25 deletions
+16
-25
host_path_test.go
pkg/volume/host_path/host_path_test.go
+2
-21
testing.go
pkg/volume/testing.go
+14
-4
No files found.
pkg/volume/host_path/host_path_test.go
View file @
6ddc30c4
...
@@ -63,7 +63,8 @@ func TestGetAccessModes(t *testing.T) {
...
@@ -63,7 +63,8 @@ func TestGetAccessModes(t *testing.T) {
func
TestRecycler
(
t
*
testing
.
T
)
{
func
TestRecycler
(
t
*
testing
.
T
)
{
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
([]
volume
.
VolumePlugin
{
&
hostPathPlugin
{
nil
,
newMockRecycler
}},
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
nil
,
nil
))
volumeHost
:=
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
nil
,
nil
)
plugMgr
.
InitPlugins
([]
volume
.
VolumePlugin
{
&
hostPathPlugin
{
nil
,
volume
.
NewFakeRecycler
}},
volumeHost
)
spec
:=
&
volume
.
Spec
{
PersistentVolume
:
&
api
.
PersistentVolume
{
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
HostPath
:
&
api
.
HostPathVolumeSource
{
Path
:
"/foo"
}}}}}
spec
:=
&
volume
.
Spec
{
PersistentVolume
:
&
api
.
PersistentVolume
{
Spec
:
api
.
PersistentVolumeSpec
{
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
HostPath
:
&
api
.
HostPathVolumeSource
{
Path
:
"/foo"
}}}}}
plug
,
err
:=
plugMgr
.
FindRecyclablePluginBySpec
(
spec
)
plug
,
err
:=
plugMgr
.
FindRecyclablePluginBySpec
(
spec
)
...
@@ -82,26 +83,6 @@ func TestRecycler(t *testing.T) {
...
@@ -82,26 +83,6 @@ func TestRecycler(t *testing.T) {
}
}
}
}
func
newMockRecycler
(
spec
*
volume
.
Spec
,
host
volume
.
VolumeHost
)
(
volume
.
Recycler
,
error
)
{
return
&
mockRecycler
{
path
:
spec
.
PersistentVolume
.
Spec
.
HostPath
.
Path
,
},
nil
}
type
mockRecycler
struct
{
path
string
host
volume
.
VolumeHost
}
func
(
r
*
mockRecycler
)
GetPath
()
string
{
return
r
.
path
}
func
(
r
*
mockRecycler
)
Recycle
()
error
{
// return nil means recycle passed
return
nil
}
func
TestPlugin
(
t
*
testing
.
T
)
{
func
TestPlugin
(
t
*
testing
.
T
)
{
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(
volume
.
VolumeConfig
{}),
volume
.
NewFakeVolumeHost
(
"fake"
,
nil
,
nil
))
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(
volume
.
VolumeConfig
{}),
volume
.
NewFakeVolumeHost
(
"fake"
,
nil
,
nil
))
...
...
pkg/volume/testing.go
View file @
6ddc30c4
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
volume
package
volume
import
(
import
(
"fmt"
"os"
"os"
"path"
"path"
...
@@ -125,7 +126,7 @@ func (plugin *FakeVolumePlugin) NewCleaner(volName string, podUID types.UID, mou
...
@@ -125,7 +126,7 @@ func (plugin *FakeVolumePlugin) NewCleaner(volName string, podUID types.UID, mou
}
}
func
(
plugin
*
FakeVolumePlugin
)
NewRecycler
(
spec
*
Spec
)
(
Recycler
,
error
)
{
func
(
plugin
*
FakeVolumePlugin
)
NewRecycler
(
spec
*
Spec
)
(
Recycler
,
error
)
{
return
&
F
akeRecycler
{
"/attributesTransferredFromSpec"
},
nil
return
&
f
akeRecycler
{
"/attributesTransferredFromSpec"
},
nil
}
}
func
(
plugin
*
FakeVolumePlugin
)
GetAccessModes
()
[]
api
.
PersistentVolumeAccessMode
{
func
(
plugin
*
FakeVolumePlugin
)
GetAccessModes
()
[]
api
.
PersistentVolumeAccessMode
{
...
@@ -162,15 +163,24 @@ func (fv *FakeVolume) TearDownAt(dir string) error {
...
@@ -162,15 +163,24 @@ func (fv *FakeVolume) TearDownAt(dir string) error {
return
os
.
RemoveAll
(
dir
)
return
os
.
RemoveAll
(
dir
)
}
}
type
F
akeRecycler
struct
{
type
f
akeRecycler
struct
{
path
string
path
string
}
}
func
(
fr
*
F
akeRecycler
)
Recycle
()
error
{
func
(
fr
*
f
akeRecycler
)
Recycle
()
error
{
// nil is success, else error
// nil is success, else error
return
nil
return
nil
}
}
func
(
fr
*
F
akeRecycler
)
GetPath
()
string
{
func
(
fr
*
f
akeRecycler
)
GetPath
()
string
{
return
fr
.
path
return
fr
.
path
}
}
func
NewFakeRecycler
(
spec
*
Spec
,
host
VolumeHost
)
(
Recycler
,
error
)
{
if
spec
.
PersistentVolume
==
nil
||
spec
.
PersistentVolume
.
Spec
.
HostPath
==
nil
{
return
nil
,
fmt
.
Errorf
(
"fakeRecycler only supports spec.PersistentVolume.Spec.HostPath"
)
}
return
&
fakeRecycler
{
path
:
spec
.
PersistentVolume
.
Spec
.
HostPath
.
Path
,
},
nil
}
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