Skip to content

test(juicefs): migrate controller tests to Ginkgo v2#5690

Open
hxrshxz wants to merge 2 commits intofluid-cloudnative:masterfrom
hxrshxz:master
Open

test(juicefs): migrate controller tests to Ginkgo v2#5690
hxrshxz wants to merge 2 commits intofluid-cloudnative:masterfrom
hxrshxz:master

Conversation

@hxrshxz
Copy link
Contributor

@hxrshxz hxrshxz commented Mar 13, 2026

Ⅰ. Describe what this PR does

Migrate pkg/controllers/v1alpha1/juicefs/ to Ginkgo v2/Gomega, adding controller unit tests with 79.1% coverage.

Ⅱ. Does this pull request fix one issue?

NONE

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

  • suite_test.go: updated to Ginkgo v2 bootstrap (removes deprecated Done channel)
  • juicefsruntime_controller_test.go: ControllerName, ManagedResource, NewRuntimeReconciler, NewCacheOption
  • implement_test.go: getRuntime (found/not-found), GetOrCreateEngine (create-error, create+cache-hit), RemoveEngine (remove/no-op), Reconcile (runtime-not-found)

Ⅳ. Describe how to verify it

go test ./pkg/controllers/v1alpha1/juicefs/... -coverprofile=coverage.out -covermode=atomic -gcflags="all=-l"
go tool cover -func=coverage.out
# Expected: coverage ≥ 79.1%

Ⅴ. Special notes for reviews

N/A

- Update suite_test.go to Ginkgo v2 (remove deprecated Done channel)
- Add implement_test.go: getRuntime, GetOrCreateEngine, RemoveEngine
- Add juicefsruntime_controller_test.go: ControllerName, ManagedResource,
  NewRuntimeReconciler, NewCacheOption
- Coverage: 79.1% (gate >75% PASS)

Signed-off-by: Harsh <harshmastic@gmail.com>
Copilot AI review requested due to automatic review settings March 13, 2026 11:15
@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Mar 13, 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 trafalgarzzz for approval by writing /assign @trafalgarzzz 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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the testing infrastructure and coverage for the JuiceFS controller. By migrating to Ginkgo v2 and Gomega, it modernizes the testing framework and introduces comprehensive unit tests for critical controller logic, ensuring greater reliability and maintainability of the codebase.

Highlights

  • Testing Framework Migration: Migrated the controller tests in pkg/controllers/v1alpha1/juicefs/ from Ginkgo v1 to Ginkgo v2 and Gomega.
  • Increased Test Coverage: Added new unit tests for the JuiceFS controller, achieving a reported test coverage of 79.1%.
  • Suite Test Update: Updated suite_test.go to use the Ginkgo v2 bootstrap, removing the deprecated Done channel and in-memory test environment setup.
  • New Controller Unit Tests: Introduced unit tests for key methods of the JuiceFSRuntimeReconciler, including ControllerName, ManagedResource, NewRuntimeReconciler, NewCacheOption, getRuntime, GetOrCreateEngine, RemoveEngine, and Reconcile.
Changelog
  • pkg/controllers/v1alpha1/juicefs/implement_test.go
    • Added a new test file to cover getRuntime, GetOrCreateEngine, RemoveEngine, and Reconcile methods.
  • pkg/controllers/v1alpha1/juicefs/juicefsruntime_controller_test.go
    • Added a new test file to cover ControllerName, ManagedResource, NewRuntimeReconciler, and NewCacheOption methods.
  • pkg/controllers/v1alpha1/juicefs/suite_test.go
    • Updated the test suite to use Ginkgo v2 bootstrap.
    • Removed the deprecated Done channel from BeforeSuite.
    • Removed the in-memory test environment setup (cfg, k8sClient, testEnv) from the suite.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Mar 13, 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
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 successfully migrates the JuiceFS controller tests to Ginkgo v2 and significantly enhances the test suite by adding comprehensive unit tests. The transition from integration-style tests using envtest to faster unit tests with a fake client is a commendable improvement. The new tests are well-structured, covering essential logic including error paths and caching mechanisms. I have one minor suggestion to improve test code conciseness.

Comment on lines +38 to +39
Expect(r.ControllerName()).To(Equal(controllerName))
Expect(r.ControllerName()).To(Equal("JuiceFSRuntimeController"))
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test contains redundant assertions. Both Expect calls verify the same condition since the unexported constant controllerName is defined as "JuiceFSRuntimeController". Please remove one of them to make the test more concise. Using the string literal is preferred as it decouples the test from the constant's implementation details.

Suggested change
Expect(r.ControllerName()).To(Equal(controllerName))
Expect(r.ControllerName()).To(Equal("JuiceFSRuntimeController"))
Expect(r.ControllerName()).To(Equal("JuiceFSRuntimeController"))

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

Migrates the JuiceFS controller tests under pkg/controllers/v1alpha1/juicefs/ to Ginkgo v2/Gomega and replaces the previous envtest-based suite scaffolding with lightweight unit-test setup using fake clients/loggers.

Changes:

  • Update suite_test.go to a Ginkgo v2 bootstrap (removing the deprecated Done channel and envtest bootstrapping).
  • Add unit tests for JuiceFSRuntimeReconciler controller helpers (ControllerName, ManagedResource, NewRuntimeReconciler, NewCacheOption).
  • Add unit tests for implementation behaviors (getRuntime, engine cache create/remove paths, and Reconcile not-found handling).

Reviewed changes

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

File Description
pkg/controllers/v1alpha1/juicefs/suite_test.go Switch to Ginkgo v2 suite bootstrap; drop envtest setup/teardown.
pkg/controllers/v1alpha1/juicefs/juicefsruntime_controller_test.go Add unit coverage for basic controller methods and cache options.
pkg/controllers/v1alpha1/juicefs/implement_test.go Add unit coverage for runtime lookup, engine caching, removal, and reconcile not-found behavior.

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

You can also share your feedback on Copilot code review. Take the survey.

Remove the duplicate assertion that tested against the unexported
constant; use the string literal form only as suggested by code review.

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

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.21%. Comparing base (a69c888) to head (72429b3).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5690   +/-   ##
=======================================
  Coverage   61.21%   61.21%           
=======================================
  Files         444      444           
  Lines       30540    30540           
=======================================
  Hits        18694    18694           
  Misses      10306    10306           
  Partials     1540     1540           

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

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.

2 participants