Skip to content

Commit

Permalink
Merge pull request #122 from Madhan-SWE/sanity_fixes
Browse files Browse the repository at this point in the history
Mocks added for statutils
  • Loading branch information
k8s-ci-robot authored Feb 16, 2022
2 parents 4cb7aae + bb1baae commit 5f11125
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion pkg/driver/sanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

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

statsUtil := MockStatSanity{
targetPath: targetPath,
}

drv := &Driver{
options: driverOptions,
controllerService: controllerService{
Expand All @@ -56,6 +60,7 @@ func TestSanity(t *testing.T) {
driverOptions: &Options{},
pvmInstanceId: "test1234",
volumeLocks: util.NewVolumeLocks(),
stats: &statsUtil,
},
}
defer func() {
Expand All @@ -82,6 +87,34 @@ func createDir(targetPath string) (string, error) {
return targetPath, nil
}

// Fake State interface methods implementation for getting
type MockStatSanity struct {
targetPath string
}

// FSInfo ...
func (su *MockStatSanity) FSInfo(path string) (int64, int64, int64, int64, int64, int64, error) {
return 1, 1, 1, 1, 1, 1, nil
}

// DeviceInfo ...
func (su *MockStatSanity) DeviceInfo(path string) (int64, error) {
return 1, nil
}

// IsBlockDevice ..
func (su *MockStatSanity) IsBlockDevice(devicePath string) (bool, error) {
if !strings.Contains(devicePath, su.targetPath) {
return false, errors.New("not a valid path")
}
return true, nil
}

func (su *MockStatSanity) IsPathNotExist(devicePath string) bool {
// return true if not matched
return !strings.Contains(devicePath, su.targetPath)
}

type fakeCloudProvider struct {
disks map[string]*fakeDisk
pub map[string]string
Expand Down

0 comments on commit 5f11125

Please sign in to comment.