Skip to content

Commit 593eda4

Browse files
committed
Add unit tests for local volume expansion
1 parent d166cab commit 593eda4

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

pkg/volume/local/local_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,37 @@ func getBlockPlugin(t *testing.T) (string, volume.BlockVolumePlugin) {
8383
return tmpDir, plug
8484
}
8585

86+
func getNodeExpandablePlugin(t *testing.T, isBlockDevice bool) (string, volume.NodeExpandableVolumePlugin) {
87+
tmpDir, err := utiltesting.MkTmpdir("localVolumeTest")
88+
if err != nil {
89+
t.Fatalf("can't make a temp dir: %v", err)
90+
}
91+
92+
plugMgr := volume.VolumePluginMgr{}
93+
var pathToFSType map[string]hostutil.FileType
94+
if isBlockDevice {
95+
pathToFSType = map[string]hostutil.FileType{
96+
tmpDir: hostutil.FileTypeBlockDev,
97+
}
98+
} else {
99+
pathToFSType = map[string]hostutil.FileType{
100+
tmpDir: hostutil.FileTypeDirectory,
101+
}
102+
}
103+
104+
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeKubeletVolumeHostWithMounterFSType(t, tmpDir, nil, nil, pathToFSType))
105+
106+
plug, err := plugMgr.FindNodeExpandablePluginByName(localVolumePluginName)
107+
if err != nil {
108+
os.RemoveAll(tmpDir)
109+
t.Fatalf("Can't find the plugin by name")
110+
}
111+
if plug.GetPluginName() != localVolumePluginName {
112+
t.Errorf("Wrong name: %s", plug.GetPluginName())
113+
}
114+
return tmpDir, plug
115+
}
116+
86117
func getPersistentPlugin(t *testing.T) (string, volume.PersistentVolumePlugin) {
87118
tmpDir, err := utiltesting.MkTmpdir("localVolumeTest")
88119
if err != nil {
@@ -148,6 +179,9 @@ func getTestVolume(readOnly bool, path string, isBlock bool, mountOptions []stri
148179
if isBlock {
149180
blockMode := v1.PersistentVolumeBlock
150181
pv.Spec.VolumeMode = &blockMode
182+
} else {
183+
fsMode := v1.PersistentVolumeFilesystem
184+
pv.Spec.VolumeMode = &fsMode
151185
}
152186
return volume.NewSpecFromPersistentVolume(pv, readOnly)
153187
}
@@ -289,6 +323,28 @@ func TestFSGlobalPathAndMountDevice(t *testing.T) {
289323
}
290324
}
291325

326+
func TestNodeExpand(t *testing.T) {
327+
// FS global path testing
328+
tmpFSDir, plug := getNodeExpandablePlugin(t, false)
329+
defer os.RemoveAll(tmpFSDir)
330+
331+
pvSpec := getTestVolume(false, tmpFSDir, false, nil)
332+
333+
resizeOptions := volume.NodeResizeOptions{
334+
VolumeSpec: pvSpec,
335+
DevicePath: tmpFSDir,
336+
}
337+
338+
// Actually, we will do no volume expansion if volume is of type dir
339+
resizeDone, err := plug.NodeExpand(resizeOptions)
340+
if err != nil {
341+
t.Fatal(err)
342+
}
343+
if !resizeDone {
344+
t.Errorf("expected resize to be done")
345+
}
346+
}
347+
292348
func TestMountUnmount(t *testing.T) {
293349
tmpDir, plug := getPlugin(t)
294350
defer os.RemoveAll(tmpDir)

0 commit comments

Comments
 (0)