Skip to content

test(csi/plugins): add Ginkgo coverage for register paths#5826

Merged
fluid-e2e-bot[bot] merged 3 commits into
fluid-cloudnative:masterfrom
hxrshxz:test/csi-plugins-register-ginkgo
May 14, 2026
Merged

test(csi/plugins): add Ginkgo coverage for register paths#5826
fluid-e2e-bot[bot] merged 3 commits into
fluid-cloudnative:masterfrom
hxrshxz:test/csi-plugins-register-ginkgo

Conversation

@hxrshxz

@hxrshxz hxrshxz commented May 3, 2026

Copy link
Copy Markdown
Contributor

Ⅰ. Describe what this PR does

Migrate the CSI plugins register coverage to Ginkgo v2 + Gomega and add package-scoped tests that raise pkg/csi/plugins coverage above the required threshold.

Ⅱ. Does this pull request fix one issue?

#5676

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Added Ginkgo unit tests for getNodeAuthorizedClientFromKubeletConfig, Register, and Enabled, and added deterministic nodeserver path tests to cover successful publish/unpublish, runtime-info fallback labeling, and clean-fuse execution paths needed for package coverage.

Ⅳ. Describe how to verify it

Run the CSI plugins package unit tests and confirm the package coverage stays above 75%.

Ⅴ. Special notes for reviews

N/A

Copilot AI review requested due to automatic review settings May 3, 2026 09:50
@fluid-e2e-bot

fluid-e2e-bot Bot commented May 3, 2026

Copy link
Copy Markdown

Hi @hxrshxz. Thanks for your PR.

I'm waiting for a fluid-cloudnative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request significantly improves test coverage for the CSI plugins by adding comprehensive unit tests for nodeserver.go and register.go. Key additions include test cases for volume publishing, unpublishing, node labeling, and mount point management, utilizing gomonkey for method patching. Feedback highlights potential brittleness when patching external methods with gomonkey and platform-dependency concerns regarding the use of null bytes in file paths for error simulation.

Comment thread pkg/csi/plugins/nodeserver_test.go Outdated

fakeMounter := mount.New("")
isLikelyNotMountPointCalls := 0
isLikelyNotMountPointPatch := gomonkey.ApplyMethod(reflect.TypeOf(fakeMounter), "IsLikelyNotMountPoint", func(_ *mount.Mounter, file string) (bool, error) {

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

Using reflect.TypeOf(fakeMounter) to patch a method from an external package like k8s.io/utils/mount can be brittle, especially if the concrete type returned by mount.New("") varies across platforms or if the method is inlined. Since fakeMounter is an interface, it's safer to use the concrete type directly if known, or ensure that the test environment is consistent. Additionally, gomonkey patching of methods in external packages often requires disabling inlining during test execution (e.g., using -gcflags=-l).

Comment thread pkg/csi/plugins/register_test.go Outdated
})

It("should return stat errors for invalid paths", func() {
clientset, err := getNodeAuthorizedClientFromKubeletConfig(string([]byte{'\x00'}))

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

Using a null byte \x00 in a file path to trigger an os.Stat error is a common trick in Go tests, but its behavior can be platform-dependent. While it works on most Unix-like systems to trigger an EINVAL or similar error, consider using a more deterministic approach for triggering specific error types if this test is intended to run in diverse environments.

Copilot AI left a comment

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.

Pull request overview

This PR migrates and expands unit test coverage for pkg/csi/plugins using Ginkgo v2 + Gomega, focusing on covering CSI plugin register paths and key nodeserver behaviors to keep package coverage above the required threshold.

Changes:

  • Added new Ginkgo specs for getNodeAuthorizedClientFromKubeletConfig, Register, and Enabled.
  • Added additional deterministic nodeserver tests to cover publish/unpublish success paths, runtime-info fuse label fallback, clean-fuse behavior, and some error branches.
  • Aligned the package test suite to run under package plugins for package-scoped coverage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/csi/plugins/register_test.go Adds package-scoped Ginkgo tests for register/kubelet-client init and plugin enablement.
pkg/csi/plugins/plugins_suite_test.go Switches suite to package plugins to support package-scoped coverage/tests.
pkg/csi/plugins/nodeserver_test.go Adds/adjusts nodeserver tests to exercise additional success and fallback branches for coverage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +492 to +498
resp, err := ns.NodeUnpublishVolume(context.Background(), req)

Expect(err).NotTo(HaveOccurred())
Expect(resp).NotTo(BeNil())
Expect(unmountCalls).To(Equal(1))
Expect(isLikelyNotMountPointCalls).To(Equal(2))
})
@codecov

codecov Bot commented May 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.36%. Comparing base (d14dcc7) to head (468fbdb).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5826      +/-   ##
==========================================
+ Coverage   59.10%   59.36%   +0.26%     
==========================================
  Files         480      480              
  Lines       32512    32512              
==========================================
+ Hits        19215    19301      +86     
+ Misses      11747    11645     -102     
- Partials     1550     1566      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cheyang cheyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

感谢贡献!几个注意点:

  1. 新增的 bind mount 成功路径测试用 gomonkey 对 cmdguard.Command 打桩,在 ARM 架构上 gomonkey 可能不稳定(因 inline function 限制)。请确认测试在 ARM runner 上也能通过。
  2. DeferCleanup 用法正确,临时目录清理及时。整体结构不错。

@cheyang cheyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

感谢贡献!几个注意点:

  1. 新增的 bind mount 成功路径测试用 gomonkey 对 cmdguard.Command 打桩,在 ARM 架构上 gomonkey 可能不稳定(因 inline function 限制)。请确认测试在 ARM runner 上也能通过。
  2. DeferCleanup 用法正确,临时目录清理及时。整体结构不错。

@cheyang

This comment has been minimized.

@cheyang

cheyang commented May 8, 2026

Copy link
Copy Markdown
Collaborator

English translation of the previous review comments:

  1. The newly added bind mount success path test uses gomonkey to stub cmdguard.Command, which may be unstable on ARM architectures (due to inline function limitations). Please confirm that the test can pass on ARM runners as well.
  2. DeferCleanup usage is correct; temporary directory cleanup is timely. Overall structure is solid.

hxrshxz added 3 commits May 11, 2026 06:46
Signed-off-by: Harsh <harshmastic@gmail.com>
Signed-off-by: Harsh <harshmastic@gmail.com>
Signed-off-by: Harsh <harshmastic@gmail.com>
@hxrshxz hxrshxz force-pushed the test/csi-plugins-register-ginkgo branch from 136652d to 468fbdb Compare May 11, 2026 01:16
@sonarqubecloud

Copy link
Copy Markdown

@hxrshxz

hxrshxz commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

Removed the fragile cmdguard.Command monkey patch from the bind mount success-path coverage, so the test no longer depends on gomonkey patching that function and should avoid the ARM inline-function instability risk.

The DeferCleanup temporary directory cleanup remains in place.

@cheyang cheyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

/lgtm

@fluid-e2e-bot

fluid-e2e-bot Bot commented May 14, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cheyang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fluid-e2e-bot fluid-e2e-bot Bot merged commit 657b933 into fluid-cloudnative:master May 14, 2026
18 checks passed
@cheyang

cheyang commented May 14, 2026

Copy link
Copy Markdown
Collaborator

/approve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants