Skip to content

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

Open
hxrshxz wants to merge 2 commits intofluid-cloudnative:masterfrom
hxrshxz:test/csi-plugins-register-ginkgo
Open

test(csi/plugins): add Ginkgo coverage for register paths#5826
hxrshxz wants to merge 2 commits intofluid-cloudnative:masterfrom
hxrshxz:test/csi-plugins-register-ginkgo

Conversation

@hxrshxz
Copy link
Copy Markdown
Contributor

@hxrshxz hxrshxz commented May 3, 2026

Ⅰ. 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

Signed-off-by: Harsh <harshmastic@gmail.com>
Copilot AI review requested due to automatic review settings May 3, 2026 09:50
@fluid-e2e-bot
Copy link
Copy Markdown

fluid-e2e-bot Bot commented May 3, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign ronggu for approval by writing /assign @ronggu in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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
Copy link
Copy Markdown

fluid-e2e-bot Bot commented May 3, 2026

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.

Copy link
Copy Markdown
Contributor

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

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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
Copy link
Copy Markdown

codecov Bot commented May 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.15%. Comparing base (3907695) to head (53ebf64).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5826      +/-   ##
==========================================
+ Coverage   58.89%   59.15%   +0.26%     
==========================================
  Files         479      479              
  Lines       32443    32443              
==========================================
+ Hits        19107    19193      +86     
+ Misses      11784    11682     -102     
- Partials     1552     1568      +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.

Signed-off-by: Harsh <harshmastic@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 3, 2026

Copy link
Copy Markdown
Collaborator

@cheyang cheyang left a comment

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 用法正确,临时目录清理及时。整体结构不错。

Copy link
Copy Markdown
Collaborator

@cheyang cheyang left a comment

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
Copy link
Copy Markdown
Collaborator

cheyang commented May 6, 2026

感谢贡献!几个注意点:

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

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