Skip to content

Commit 468fbdb

Browse files
committed
test(csi/plugins): avoid fragile bind mount command patch
Signed-off-by: Harsh <harshmastic@gmail.com>
1 parent 6e4320b commit 468fbdb

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

pkg/csi/plugins/nodeserver_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ var _ = Describe("NodeServer", func() {
304304

305305
fluidPath := filepath.Join(tempDir, "runtime", testName)
306306
targetPath := filepath.Join(tempDir, "target")
307+
fakeMountPath := filepath.Join(tempDir, "mount")
308+
originalPath := os.Getenv("PATH")
307309

308310
isMountedPatch := gomonkey.ApplyFunc(utils.IsMounted, func(absPath string) (bool, error) {
309311
return false, os.ErrNotExist
@@ -315,10 +317,11 @@ var _ = Describe("NodeServer", func() {
315317
})
316318
defer mountReadyPatch.Reset()
317319

318-
commandPatch := gomonkey.ApplyFunc(cmdguard.Command, func(name string, arg ...string) (*exec.Cmd, error) {
319-
return exec.Command("sh", "-c", "exit 0"), nil
320+
Expect(os.WriteFile(fakeMountPath, []byte("#!/bin/sh\nexit 0\n"), 0755)).To(Succeed())
321+
Expect(os.Setenv("PATH", tempDir+string(os.PathListSeparator)+originalPath)).To(Succeed())
322+
DeferCleanup(func() {
323+
Expect(os.Setenv("PATH", originalPath)).To(Succeed())
320324
})
321-
defer commandPatch.Reset()
322325

323326
req := &csi.NodePublishVolumeRequest{
324327
VolumeId: testVolumeID,

0 commit comments

Comments
 (0)