Skip to content

test(fluidapp): add Ginkgo controller unit coverage#5828

Open
hxrshxz wants to merge 2 commits intofluid-cloudnative:masterfrom
hxrshxz:test/fluidapp-ut-week10-ginkgo
Open

test(fluidapp): add Ginkgo controller unit coverage#5828
hxrshxz wants to merge 2 commits intofluid-cloudnative:masterfrom
hxrshxz:test/fluidapp-ut-week10-ginkgo

Conversation

@hxrshxz
Copy link
Copy Markdown
Contributor

@hxrshxz hxrshxz commented May 3, 2026

I.

Add Ginkgo v2 + Gomega unit coverage for the fluidapp controller package and migrate the touched fluidapp tests to the repo’s current testing style.

II.

#5676

III.

Added a package-level Ginkgo suite bootstrap, migrated implement_test.go from stdlib testing to Ginkgo/Gomega, and added fluidapp_controller_ut_test.go to cover constructor/accessor behavior plus Reconcile and internalReconcile paths.

IV.

Run the fluidapp controller package tests and confirm the package coverage stays above the required threshold.

V.

N/A

Signed-off-by: Harsh <harshmastic@gmail.com>
Copilot AI review requested due to automatic review settings May 3, 2026 10:44
@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 cheyang for approval by writing /assign @cheyang 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

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 the pkg/controllers/v1alpha1/fluidapp unit tests to the repository’s current Ginkgo/Gomega style and adds controller-focused unit coverage for the FluidApp reconciler package. It fits into the broader repo effort to standardize testing and raise per-package coverage.

Changes:

  • Added a package-level Ginkgo suite bootstrap for the fluidapp controller package.
  • Migrated implement_test.go from stdlib testing table tests to Ginkgo/Gomega specs.
  • Added fluidapp_controller_ut_test.go to cover reconciler construction, simple accessors, and selected Reconcile / internalReconcile paths.

Reviewed changes

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

File Description
pkg/controllers/v1alpha1/fluidapp/suite_test.go Adds the Ginkgo suite entrypoint and test logger setup for the package.
pkg/controllers/v1alpha1/fluidapp/implement_test.go Rewrites fuse-sidecar unmount tests into Ginkgo specs.
pkg/controllers/v1alpha1/fluidapp/fluidapp_controller_ut_test.go Adds new unit coverage for reconciler helpers and main reconcile flows.

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

Comment on lines +55 to +58
It("returns nil when the fuse sidecar has no mount path", func() {
patches = gomonkey.ApplyFunc(kubeclient.ExecCommandInContainerWithContext, func(context.Context, string, string, string, []string) (string, string, error) {
return "", "", nil
})
Comment on lines +113 to +118
It("unmounts each fuse sidecar container", func() {
patches = gomonkey.ApplyFunc(kubeclient.ExecCommandInContainerWithContext, func(_ context.Context, _, containerName, _ string, cmd []string) (string, string, error) {
Expect(containerName).To(ContainSubstring(common.FuseContainerName))
Expect(cmd).To(Equal([]string{"umount", expectedJuiceFSMountCmd}))
return "", "", nil
})
Comment on lines +82 to +83
Describe("Reconcile", func() {
It("returns no requeue when the pod does not exist", func() {
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 transitions the FluidApp controller tests to the Ginkgo/Gomega framework, adding a new test suite and refactoring existing implementation tests. The review feedback highlights a potential mismatch in a hardcoded unmount path constant and suggests improvements for test stability, such as addressing the thread-safety of gomonkey patches and ensuring robust cleanup using AfterEach blocks.

}},
}},
var _ = Describe("FluidAppReconcilerImplement", func() {
const expectedJuiceFSMountCmd = "/mnt/jfs/juicefs-fuse"
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 constant expectedJuiceFSMountCmd includes a hardcoded suffix /juicefs-fuse which seems inconsistent with the MountPath defined in the test cases (e.g., line 105 uses /mnt/jfs). If kubeclient.GetMountPathInContainer simply returns the mount path, the unmount command should be umount /mnt/jfs. Please verify if this suffix is intentional or if it should match the MountPath exactly.

Suggested change
const expectedJuiceFSMountCmd = "/mnt/jfs/juicefs-fuse"
const expectedJuiceFSMountCmd = "/mnt/jfs"

Comment on lines +155 to +159
patches := gomonkey.ApplyFunc((*FluidAppReconcilerImplement).umountFuseSidecars, func(_ *FluidAppReconcilerImplement, gotPod *corev1.Pod) error {
Expect(gotPod.Name).To(Equal(testPodName))
return nil
})
defer patches.Reset()
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 gomonkey.ApplyFunc to patch methods is globally scoped and not thread-safe. If this test suite is executed in parallel with other tests that also patch the same method or rely on its original behavior, it will lead to race conditions and flaky tests. Consider using an interface-based mocking approach or ensure that parallel execution is disabled for this package.

Comment on lines +155 to +159
patches := gomonkey.ApplyFunc((*FluidAppReconcilerImplement).umountFuseSidecars, func(_ *FluidAppReconcilerImplement, gotPod *corev1.Pod) error {
Expect(gotPod.Name).To(Equal(testPodName))
return nil
})
defer patches.Reset()
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 implement_test.go, consider declaring the patches variable at the Describe block level and resetting it in an AfterEach block. This ensures that patches are always cleaned up even if a test panics before reaching the defer statement.

@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 58.89%. Comparing base (3907695) to head (80a6c8a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5828   +/-   ##
=======================================
  Coverage   58.89%   58.89%           
=======================================
  Files         479      479           
  Lines       32443    32443           
=======================================
  Hits        19107    19107           
  Misses      11784    11784           
  Partials     1552     1552           

☔ 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. patches 变量在 Describe 作用域声明,但 AfterEach 重置逻辑依赖 It 内赋值。建议每个 Context/It 内局部创建 patches 并用 defer Reset(),避免跨测试残留。
  2. 可以考虑补充 Reconcile 中更多错误路径的覆盖(如 updateStatus 失败)。

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. patches 变量在 Describe 作用域声明,但 AfterEach 重置逻辑依赖 It 内赋值。建议每个 Context/It 内局部创建 patches 并用 defer Reset(),避免跨测试残留。
  2. 可以考虑补充 Reconcile 中更多错误路径的覆盖(如 updateStatus 失败)。

@cheyang
Copy link
Copy Markdown
Collaborator

cheyang commented May 6, 2026

感谢贡献!几个建议:

  1. patches 变量在 Describe 作用域声明,但 AfterEach 重置逻辑依赖 It 内赋值。建议每个 Context/It 内局部创建 patches 并用 defer Reset(),避免跨测试残留。
  2. 可以考虑补充 Reconcile 中更多错误路径的覆盖(如 updateStatus 失败)。

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