Skip to content

test(efc): migrate pkg/controllers/v1alpha1/efc to Ginkgo v2 with fake-client unit tests#5698

Open
hxrshxz wants to merge 2 commits intofluid-cloudnative:masterfrom
hxrshxz:test/efc-ginkgo-v2-tests
Open

test(efc): migrate pkg/controllers/v1alpha1/efc to Ginkgo v2 with fake-client unit tests#5698
hxrshxz wants to merge 2 commits intofluid-cloudnative:masterfrom
hxrshxz:test/efc-ginkgo-v2-tests

Conversation

@hxrshxz
Copy link
Contributor

@hxrshxz hxrshxz commented Mar 18, 2026

Ⅰ. Describe what this PR does

Migrate the pkg/controllers/v1alpha1/efc package tests from the legacy Ginkgo v1 + envtest bootstrap to Ginkgo v2 with lightweight fake-client unit tests covering all non-infrastructure functions.

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

Updated pkg/controllers/v1alpha1/efc/suite_test.go to use a lightweight Ginkgo v2 bootstrap with fake.NullLogger(), added pkg/controllers/v1alpha1/efc/efcruntime_controller_test.go for controller helper coverage, and added pkg/controllers/v1alpha1/efc/implement_test.go for getRuntime, GetOrCreateEngine, RemoveEngine, and the not-found Reconcile path. The package now has 10 passing specs and 78.6% statement coverage.

Ⅳ. Describe how to verify it

Run go test ./pkg/controllers/v1alpha1/efc/... -count=1 -v, then run go test -coverprofile=/tmp/fluid-efc.cover ./pkg/controllers/v1alpha1/efc/... -count=1 and go tool cover -func=/tmp/fluid-efc.cover to confirm coverage stays above 75%. Optionally run go vet ./pkg/controllers/v1alpha1/efc/....

Ⅴ. Special notes for reviews

N/A

Copilot AI review requested due to automatic review settings March 18, 2026 11:01
@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Mar 18, 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 refactors the testing approach for the EFC controller, moving from a heavier integration-style setup to a more agile and focused unit testing methodology. This change aims to improve test execution speed, maintainability, and provide more granular coverage for core controller logic, ensuring robust functionality without relying on a full Kubernetes environment.

Highlights

  • Testing Framework Migration: The testing framework for the pkg/controllers/v1alpha1/efc package has been migrated from Ginkgo v1 with envtest to Ginkgo v2, utilizing lightweight fake-client unit tests.
  • Expanded Unit Test Coverage: New unit tests have been added to cover non-infrastructure functions within the EFC controller, specifically for efcruntime_controller_test.go and implement_test.go.
  • Improved Test Bootstrap: The test suite now uses a lightweight Ginkgo v2 bootstrap with fake.NullLogger(), removing the need for a full envtest setup for these unit tests.
  • Increased Code Coverage: The changes have resulted in 10 passing specs and an increased statement coverage of 78.6% for the package.
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.

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 18, 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 EFC controller tests to Ginkgo v2 with fake-client unit tests, which is a significant improvement for test efficiency. The new tests are well-structured and cover essential controller logic. I have one suggestion regarding the usage of context in the test files to align with best practices.


It("should return the runtime when it exists in the cluster", func() {
ctx := cruntime.ReconcileRequestContext{
Context: context.TODO(),
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

In tests, it is a better practice to use context.Background() instead of context.TODO(). context.Background() is intended for top-level contexts in tests and initializations, whereas context.TODO() is a placeholder for when the correct context is not yet known. Please apply this change to all other occurrences of context.TODO() in this file.

Suggested change
Context: context.TODO(),
Context: context.Background(),

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 pkg/controllers/v1alpha1/efc tests from envtest-based integration style to Ginkgo v2 + controller-runtime fake-client unit tests, improving speed and isolating controller helper behavior.

Changes:

  • Replaced envtest bootstrap in suite_test.go with a lightweight Ginkgo v2 suite using fake.NullLogger().
  • Added unit tests for controller helpers (ControllerName, ManagedResource, NewRuntimeReconciler).
  • Added unit tests for getRuntime, GetOrCreateEngine, RemoveEngine, and the “runtime not found” Reconcile path.

Reviewed changes

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

File Description
pkg/controllers/v1alpha1/efc/suite_test.go Removes envtest setup; uses lightweight Ginkgo v2 bootstrap with null logger.
pkg/controllers/v1alpha1/efc/implement_test.go Adds fake-client unit tests covering helper methods and not-found reconcile behavior.
pkg/controllers/v1alpha1/efc/efcruntime_controller_test.go Adds unit tests for controller identity and managed resource metadata.

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

@hxrshxz
Copy link
Contributor Author

hxrshxz commented Mar 18, 2026

/gemini review

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 effectively migrates the tests for the pkg/controllers/v1alpha1/efc package to Ginkgo v2 with a fake client, which is a commendable improvement for test efficiency. The new tests are well-written and cover the intended functionality. My review includes a couple of suggestions to further simplify the test setup code by removing redundant scheme initializations, leveraging the provided helper function more effectively.

@hxrshxz
Copy link
Contributor Author

hxrshxz commented Mar 18, 2026

/gemini review

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 effectively migrates the EFC controller tests to use Ginkgo v2 with a fake client, which is a significant improvement over the previous envtest-based approach. This change simplifies the test setup and should result in faster test execution. The new tests are well-structured and cover the intended functionality. I have one minor suggestion to make an assertion more precise.

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.22%. Comparing base (50940f8) to head (c0c8c17).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5698   +/-   ##
=======================================
  Coverage   61.22%   61.22%           
=======================================
  Files         444      444           
  Lines       30557    30557           
=======================================
  Hits        18710    18710           
  Misses      10307    10307           
  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.

hxrshxz added 2 commits March 18, 2026 17:33
Signed-off-by: Harsh <harshmastic@gmail.com>
Signed-off-by: Harsh <harshmastic@gmail.com>
@hxrshxz hxrshxz force-pushed the test/efc-ginkgo-v2-tests branch from 7b31315 to c0c8c17 Compare March 18, 2026 12:03
@sonarqubecloud
Copy link

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