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
a5feac57
Commit
a5feac57
authored
Sep 07, 2015
by
markturansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved recycler unit test
parent
616ba4ea
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 @
a5feac57
...
@@ -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 @
a5feac57
...
@@ -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