-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Viktor Kramarenko <viktor.kramarenko@flant.com>
- Loading branch information
1 parent
b652481
commit 13ef205
Showing
4 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
images/sds-local-volume-csi/pkg/utils/node_store_maganer_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
mountutils "k8s.io/mount-utils" | ||
"sds-local-volume-csi/pkg/logger" | ||
) | ||
|
||
func TestNodeStoreManager(t *testing.T) { | ||
t.Run("toMapperPath", func(t *testing.T) { | ||
t.Run("does_not_have_prefix_returns_empty", func(t *testing.T) { | ||
assert.Equal(t, "", toMapperPath("not-dev-path")) | ||
}) | ||
|
||
t.Run("have_prefix_returns_path", func(t *testing.T) { | ||
path := "/dev/some-good/path" | ||
expected := "/dev/mapper/some--good-path" | ||
|
||
assert.Equal(t, expected, toMapperPath(path)) | ||
}) | ||
}) | ||
|
||
t.Run("checkMount", func(t *testing.T) { | ||
t.Run("all_good", func(t *testing.T) { | ||
const ( | ||
devPath = "/dev/some-good/path" | ||
target = "some-target" | ||
) | ||
f := &mountutils.FakeMounter{} | ||
f.MountPoints = []mountutils.MountPoint{ | ||
{ | ||
Device: devPath, | ||
Path: target, | ||
}, | ||
} | ||
store := &Store{ | ||
Log: &logger.Logger{}, | ||
NodeStorage: mountutils.SafeFormatAndMount{ | ||
Interface: f, | ||
}, | ||
} | ||
|
||
err := checkMount(store, devPath, target, []string{}) | ||
assert.NoError(t, err) | ||
}) | ||
|
||
t.Run("device_is_not_devPath_nor_mapperDevPath_returns_error", func(t *testing.T) { | ||
const ( | ||
devPath = "weird-path" | ||
target = "some-target" | ||
) | ||
f := &mountutils.FakeMounter{} | ||
f.MountPoints = []mountutils.MountPoint{ | ||
{ | ||
Device: "other-name", | ||
Path: target, | ||
}, | ||
} | ||
store := &Store{ | ||
Log: &logger.Logger{}, | ||
NodeStorage: mountutils.SafeFormatAndMount{ | ||
Interface: f, | ||
}, | ||
} | ||
|
||
err := checkMount(store, devPath, target, []string{}) | ||
assert.ErrorContains(t, err, "[checkMount] device from mount point \"other-name\" does not match expected source device path weird-path or mapper device path ") | ||
}) | ||
|
||
t.Run("path_is_not_target_returns_error", func(t *testing.T) { | ||
const ( | ||
devPath = "weird-path" | ||
target = "some-target" | ||
) | ||
f := &mountutils.FakeMounter{} | ||
f.MountPoints = []mountutils.MountPoint{ | ||
{ | ||
Device: devPath, | ||
Path: "other-path", | ||
}, | ||
} | ||
store := &Store{ | ||
Log: &logger.Logger{}, | ||
NodeStorage: mountutils.SafeFormatAndMount{ | ||
Interface: f, | ||
}, | ||
} | ||
|
||
err := checkMount(store, devPath, target, []string{}) | ||
assert.ErrorContains(t, err, "[checkMount] mount point \"some-target\" not found in mount info") | ||
}) | ||
}) | ||
} |
File renamed without changes.
113 changes: 113 additions & 0 deletions
113
images/sds-local-volume-scheduler-extender/src/pkg/controller/lvg_watcher_cache_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package controller | ||
|
||
import ( | ||
snc "github.com/deckhouse/sds-node-configurator/api/v1alpha1" | ||
"github.com/stretchr/testify/assert" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"testing" | ||
) | ||
|
||
func TestLVGWatcherCache(t *testing.T) { | ||
t.Run("shouldReconcileLVG", func(t *testing.T) { | ||
t.Run("deletion_timestamp_not_nil_returns_false", func(t *testing.T) { | ||
lvg := &snc.LvmVolumeGroup{} | ||
lvg.DeletionTimestamp = &v1.Time{} | ||
|
||
assert.False(t, shouldReconcileLVG(&snc.LvmVolumeGroup{}, lvg)) | ||
}) | ||
|
||
t.Run("allocated_size_and_status_thin_pools_equal_returns_false", func(t *testing.T) { | ||
size := resource.MustParse("1G") | ||
thinPools := []snc.LvmVolumeGroupThinPoolStatus{ | ||
{ | ||
Name: "thin", | ||
ActualSize: resource.MustParse("1G"), | ||
}, | ||
} | ||
oldLvg := &snc.LvmVolumeGroup{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "first", | ||
}, | ||
Status: snc.LvmVolumeGroupStatus{ | ||
AllocatedSize: size, | ||
ThinPools: thinPools, | ||
}, | ||
} | ||
newLvg := &snc.LvmVolumeGroup{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "first", | ||
}, | ||
Status: snc.LvmVolumeGroupStatus{ | ||
AllocatedSize: size, | ||
ThinPools: thinPools, | ||
}, | ||
} | ||
|
||
assert.False(t, shouldReconcileLVG(oldLvg, newLvg)) | ||
}) | ||
|
||
t.Run("allocated_size_not_equal_returns_true", func(t *testing.T) { | ||
thinPools := []snc.LvmVolumeGroupThinPoolStatus{ | ||
{ | ||
Name: "thin", | ||
ActualSize: resource.MustParse("1G"), | ||
}, | ||
} | ||
oldLvg := &snc.LvmVolumeGroup{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "first", | ||
}, | ||
Status: snc.LvmVolumeGroupStatus{ | ||
AllocatedSize: resource.MustParse("1G"), | ||
ThinPools: thinPools, | ||
}, | ||
} | ||
newLvg := &snc.LvmVolumeGroup{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "first", | ||
}, | ||
Status: snc.LvmVolumeGroupStatus{ | ||
AllocatedSize: resource.MustParse("2G"), | ||
ThinPools: thinPools, | ||
}, | ||
} | ||
|
||
assert.True(t, shouldReconcileLVG(oldLvg, newLvg)) | ||
}) | ||
|
||
t.Run("status_thin_pools_not_equal_returns_false", func(t *testing.T) { | ||
size := resource.MustParse("1G") | ||
oldLvg := &snc.LvmVolumeGroup{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "first", | ||
}, | ||
Status: snc.LvmVolumeGroupStatus{ | ||
AllocatedSize: size, | ||
ThinPools: []snc.LvmVolumeGroupThinPoolStatus{ | ||
{ | ||
Name: "thin", | ||
ActualSize: resource.MustParse("1G"), | ||
}, | ||
}, | ||
}, | ||
} | ||
newLvg := &snc.LvmVolumeGroup{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "first", | ||
}, | ||
Status: snc.LvmVolumeGroupStatus{ | ||
AllocatedSize: size, | ||
ThinPools: []snc.LvmVolumeGroupThinPoolStatus{ | ||
{ | ||
Name: "thin", | ||
ActualSize: resource.MustParse("2G"), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
assert.True(t, shouldReconcileLVG(oldLvg, newLvg)) | ||
}) | ||
}) | ||
} |