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
13 changes: 13 additions & 0 deletions pkg/ddc/alluxio/operations/cached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ import (
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
)

// TestAlluxioFileUtils_CachedState verifies CachedState behavior for two core paths: when
// exec fails the error is returned, and when exec succeeds the cache size is parsed from
// the "Alluxio cluster summary" output (expecting 0B -> cached size 0).
//
// Parameters:
// - t (*testing.T): The test handle used for reporting failures.
//
// Returns:
// - none
//
// Notes:
// - Mocks AlluxioFileUtils.exec to simulate error and successful command output.
// - Asserts both error handling and cache size parsing correctness.
Comment on lines +27 to +39
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

The documentation style using explicit Parameters:, Returns:, and Notes: sections is not idiomatic for Go. According to the Go Code Review Comments, doc comments should be concise paragraphs starting with the function name. For test functions, documenting the *testing.T parameter and a none return is considered unnecessary noise.

Suggested change
// TestAlluxioFileUtils_CachedState verifies CachedState behavior for two core paths: when
// exec fails the error is returned, and when exec succeeds the cache size is parsed from
// the "Alluxio cluster summary" output (expecting 0B -> cached size 0).
//
// Parameters:
// - t (*testing.T): The test handle used for reporting failures.
//
// Returns:
// - none
//
// Notes:
// - Mocks AlluxioFileUtils.exec to simulate error and successful command output.
// - Asserts both error handling and cache size parsing correctness.
// TestAlluxioFileUtils_CachedState verifies CachedState behavior by mocking
// AlluxioFileUtils.exec. It ensures that errors are returned when execution fails
// and that the cache size is correctly parsed from the "Alluxio cluster summary"
// output (e.g., "0B" is parsed as 0).
References
  1. Doc comments should be complete sentences, starting with the name of the thing being declared. They should be plain text paragraphs without explicit sections like 'Parameters' or 'Returns' unless necessary for complex logic, which is rarely the case for tests. (link)

func TestAlluxioFileUtils_CachedState(t *testing.T) {
ExecCommon := func(a AlluxioFileUtils, command []string, verbose bool) (stdout string, stderr string, err error) {
return "Alluxio cluster summary: \n Master Address: 192.168.0.193:20009 \n Used Capacity: 0B\n", "", nil
Expand Down
Loading