Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/ddc/alluxio/operations/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ func TestAlluxioFileUtils_MasterPodName(t *testing.T) {
}

func TestAlluxioFileUtils_ExecMountScripts(t *testing.T) {
// Mock exec to avoid invoking the mounted script during the unit test.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The mock functions ExecCommon (line 646) and ExecErr (line 649) are missing the receiver argument in their signatures. When patching a method with gomonkey.ApplyPrivateMethod, the mock function must include the receiver as its first argument (e.g., func(a AlluxioFileUtils, command []string, verbose bool)). This likely causes the test to fail or not apply the mock correctly, as seen in other tests in this file (e.g., line 134).

ExecCommon := func(command []string, verbose bool) (stdout string, stderr string, err error) {
return strings.Join(command, " "), "", nil
}
Expand All @@ -652,13 +653,15 @@ func TestAlluxioFileUtils_ExecMountScripts(t *testing.T) {
a := &AlluxioFileUtils{log: fake.NullLogger()}
patch1 := gomonkey.ApplyPrivateMethod(*a, "exec", ExecErr)

// ExecMountScripts should return the error reported by exec.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other tests in this file (e.g., lines 141, 165, 189), consider using reflect.TypeOf(AlluxioFileUtils{}) instead of the instance *a as the first argument to gomonkey.ApplyPrivateMethod on lines 654 and 663.

err := a.ExecMountScripts()
if err == nil {
t.Error("check failure, want err, got nil")
}
patch1.Reset()

patch2 := gomonkey.ApplyPrivateMethod(*a, "exec", ExecCommon)
// ExecMountScripts should complete without error when exec succeeds.
err = a.ExecMountScripts()
if err != nil {
t.Errorf("check failure, want nil, got err: %v", err)
Expand Down
Loading