Skip to content

Commit 5f11125

Browse files
authored
Merge pull request #122 from Madhan-SWE/sanity_fixes
Mocks added for statutils
2 parents 4cb7aae + bb1baae commit 5f11125

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

pkg/driver/sanity_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
func TestSanity(t *testing.T) {
2222
// Setup the full driver and its environment
23-
dir, err := ioutil.TempDir("", "sanity-ebs-csi")
23+
dir, err := ioutil.TempDir("", "sanity-powervs-csi")
2424
if err != nil {
2525
t.Fatalf("error creating directory %v", err)
2626
}
@@ -43,6 +43,10 @@ func TestSanity(t *testing.T) {
4343
mode: AllMode,
4444
}
4545

46+
statsUtil := MockStatSanity{
47+
targetPath: targetPath,
48+
}
49+
4650
drv := &Driver{
4751
options: driverOptions,
4852
controllerService: controllerService{
@@ -56,6 +60,7 @@ func TestSanity(t *testing.T) {
5660
driverOptions: &Options{},
5761
pvmInstanceId: "test1234",
5862
volumeLocks: util.NewVolumeLocks(),
63+
stats: &statsUtil,
5964
},
6065
}
6166
defer func() {
@@ -82,6 +87,34 @@ func createDir(targetPath string) (string, error) {
8287
return targetPath, nil
8388
}
8489

90+
// Fake State interface methods implementation for getting
91+
type MockStatSanity struct {
92+
targetPath string
93+
}
94+
95+
// FSInfo ...
96+
func (su *MockStatSanity) FSInfo(path string) (int64, int64, int64, int64, int64, int64, error) {
97+
return 1, 1, 1, 1, 1, 1, nil
98+
}
99+
100+
// DeviceInfo ...
101+
func (su *MockStatSanity) DeviceInfo(path string) (int64, error) {
102+
return 1, nil
103+
}
104+
105+
// IsBlockDevice ..
106+
func (su *MockStatSanity) IsBlockDevice(devicePath string) (bool, error) {
107+
if !strings.Contains(devicePath, su.targetPath) {
108+
return false, errors.New("not a valid path")
109+
}
110+
return true, nil
111+
}
112+
113+
func (su *MockStatSanity) IsPathNotExist(devicePath string) bool {
114+
// return true if not matched
115+
return !strings.Contains(devicePath, su.targetPath)
116+
}
117+
85118
type fakeCloudProvider struct {
86119
disks map[string]*fakeDisk
87120
pub map[string]string

0 commit comments

Comments
 (0)