Skip to content

test(alluxio): migrate suite to Ginkgo v2 and add unit tests for controller and implement#5686

Draft
hxrshxz wants to merge 1 commit intofluid-cloudnative:masterfrom
hxrshxz:test/alluxio-controller-ginkgo-v2
Draft

test(alluxio): migrate suite to Ginkgo v2 and add unit tests for controller and implement#5686
hxrshxz wants to merge 1 commit intofluid-cloudnative:masterfrom
hxrshxz:test/alluxio-controller-ginkgo-v2

Conversation

@hxrshxz
Copy link
Contributor

@hxrshxz hxrshxz commented Mar 9, 2026

Ⅰ. Describe what this PR does

Migrate the AlluxioRuntime controller package to Ginkgo v2 suite style and add unit tests covering NewRuntimeReconciler, ControllerName, Reconcile, getRuntime, GetOrCreateEngine, and RemoveEngine.

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

  • implement_test.go: getRuntime — returns runtime when present, errors when absent; RemoveEngine — removes entry, no-op when missing; GetOrCreateEngine — returns error for unknown engine impl
  • alluxio_runtime_controller_test.go: NewRuntimeReconciler — fields initialised; ControllerName — returns expected constant; Reconcile — early-exit on not-found runtime, proceeds past getRuntime when runtime exists

Ⅳ. Describe how to verify it

KUBEBUILDER_ASSETS=$HOME/.local/share/kubebuilder-envtest/k8s/1.29.0-linux-amd64 \
  go test -v -cover ./pkg/controllers/v1alpha1/alluxio/... -count=1
# Expected: 9 specs pass, coverage: 89.7%

Ⅴ. Special notes for reviews

N/A

Copilot AI review requested due to automatic review settings March 9, 2026 19:47
@fluid-e2e-bot
Copy link

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

fluid-e2e-bot bot commented Mar 9, 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.

@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 test coverage and modernizes the testing framework for the AlluxioRuntime controller. By migrating to Ginkgo v2 and adding comprehensive unit tests for key controller and implementation methods, it improves the reliability and maintainability of the Alluxio integration. The changes ensure that core functionalities like runtime reconciliation, engine management, and object retrieval behave as expected under various conditions.

Highlights

  • Ginkgo v2 Migration: The AlluxioRuntime controller package has been migrated to use the Ginkgo v2 suite style, updating test suite setup accordingly.
  • Controller Unit Tests Added: New unit tests have been added for the AlluxioRuntimeController covering NewRuntimeReconciler, ControllerName, and Reconcile methods.
  • Implementation Unit Tests Added: Unit tests have been introduced for the controller's internal implementation, specifically for getRuntime, RemoveEngine, and GetOrCreateEngine functions.
Changelog
  • pkg/controllers/v1alpha1/alluxio/alluxio_runtime_controller_test.go
    • Added new test file for AlluxioRuntimeController.
    • Included tests for NewRuntimeReconciler to verify proper initialization of controller fields.
    • Added tests for ControllerName to ensure the correct constant name is returned.
    • Implemented tests for Reconcile to cover scenarios where the AlluxioRuntime is not found and when it exists.
  • pkg/controllers/v1alpha1/alluxio/implement_test.go
    • Added new test file for internal implementation functions.
    • Included tests for getRuntime to check retrieval of existing runtimes and error handling for missing ones.
    • Added tests for RemoveEngine to verify engine removal from the map and ensure no-op behavior for non-existent engines.
    • Implemented tests for GetOrCreateEngine to confirm error handling for unknown engine implementations.
  • pkg/controllers/v1alpha1/alluxio/suite_test.go
    • Removed unused os import.
    • Removed the useExistingCluster variable.
    • Updated the BeforeSuite function signature to align with Ginkgo v2, removing the done parameter.
    • Removed the close(done) call from BeforeSuite.
Activity
  • No specific review comments or discussions were noted in the provided context.
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.

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 Alluxio controller test suite to Ginkgo v2 style and adds unit tests for key controller and implement behaviors.

Changes:

  • Updated the controller suite bootstrap from Ginkgo v1 BeforeSuite(done Done) to Ginkgo v2 BeforeSuite(func())
  • Added unit tests for getRuntime, engine map management (GetOrCreateEngine, RemoveEngine), and controller basics (NewRuntimeReconciler, ControllerName, Reconcile)
  • Simplified suite configuration by removing existing-cluster toggling

Reviewed changes

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

File Description
pkg/controllers/v1alpha1/alluxio/suite_test.go Migrates suite setup to Ginkgo v2 BeforeSuite style and adjusts envtest bootstrap behavior
pkg/controllers/v1alpha1/alluxio/implement_test.go Adds unit tests for getRuntime, RemoveEngine, and GetOrCreateEngine
pkg/controllers/v1alpha1/alluxio/alluxio_runtime_controller_test.go Adds unit tests for controller construction, naming, and Reconcile 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.

Comment on lines 50 to 54
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
if env := os.Getenv("USE_EXISTING_CLUSTER"); env == "true" {
useExistingCluster = true
}

By("bootstrapping test environment")
testEnv = &envtest.Environment{
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The prior Ginkgo v1 suite used an explicit 60s timeout for BeforeSuite, but the v2 migration removes it. If envtest startup hangs (assets missing, etc.), the suite may block indefinitely. Consider adding an explicit Ginkgo v2 timeout (e.g., a NodeTimeout(...) option on BeforeSuite or suite-level timeout configuration) to restore the previous bounded behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +113 to +115
if err != nil {
Expect(err.Error()).ToNot(ContainSubstring("not found"))
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

This assertion is brittle and can fail for legitimate reasons: ReconcileInternal may attempt to fetch other resources (the comment even mentions a missing Dataset) which can also produce a "not found" error string. Instead of substring-matching the error message, prefer a structured check (e.g., use Kubernetes apierrors.IsNotFound(err) and, if it's NotFound, assert the missing kind/resource matches the AlluxioRuntime rather than any dependency), or restructure the test to isolate/verify only the getRuntime portion (e.g., by directly testing getRuntime or mocking/stubbing the internal reconcile step).

Copilot uses AI. Check for mistakes.
Comment on lines +108 to +111
// Inject a sentinel value directly so we can verify removal.
r.mutex.Lock()
r.engines[id] = nil
r.mutex.Unlock()
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

Using nil as the sentinel map value makes this test less robust: depending on RemoveEngine's implementation, code might treat a nil interface value as equivalent to an absent engine (or skip deletion when the value is nil). It’s safer to store a non-nil fake/stub base.Engine implementation so the test definitively exercises the 'engine present' removal behavior.

Copilot uses AI. Check for mistakes.
@hxrshxz
Copy link
Contributor Author

hxrshxz commented Mar 9, 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 successfully migrates the Alluxio test suite to Ginkgo v2 and expands unit test coverage for the controller and its implementation. The changes are well-structured and the new tests cover important functions. My review includes a few suggestions to further improve the tests: consistently using context.Background() instead of context.TODO() for root contexts in tests, and strengthening a test assertion in alluxio_runtime_controller_test.go to more accurately reflect the behavior under test.

I am having trouble creating individual review comments. Click here to see my feedback.

pkg/controllers/v1alpha1/alluxio/alluxio_runtime_controller_test.go (85)

medium

In Go tests, it's a best practice to use context.Background() for the root context of a test case instead of context.TODO(). This makes the intent clearer that you are starting a new context tree for the test.

result, err := r.Reconcile(context.Background(), req)

pkg/controllers/v1alpha1/alluxio/alluxio_runtime_controller_test.go (110-115)

medium

This test's assertion could be stronger, and the accompanying comment is misleading. When a Dataset is missing, ReconcileInternal returns a requeue result, not an error. This means err is nil, and the if err != nil block is dead code in this scenario.

To make the test more accurate, you should assert that a requeue is requested. This also provides an opportunity to use context.Background() as per Go testing best practices.

result, err := r.Reconcile(context.Background(), req)
Expect(err).ToNot(HaveOccurred())
Expect(result.Requeue).To(BeTrue())

pkg/controllers/v1alpha1/alluxio/implement_test.go (75)

medium

In Go tests, it's a best practice to use context.Background() for the root context of a test case instead of context.TODO(). This makes the intent clearer that you are starting a new context tree for the test. This improvement can be applied to all uses of context.TODO() in this file.

Context:        context.Background(),

@hxrshxz hxrshxz marked this pull request as draft March 9, 2026 20:12
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 Alluxio controller test suite to Ginkgo v2 and adds several new unit tests, significantly improving test coverage. The changes are well-structured. My review includes a few suggestions to further improve the new tests, mainly focusing on strengthening an assertion to check for an expected error instead of just a lack of panic, and consistently using context.Background() instead of context.TODO() for clarity in test contexts.

Comment on lines +107 to +111
// Reconcile proceeds past getRuntime, builds the engine, then hits the
// "no dataset bound" branch which returns RequeueAfter(5s) with no error.
result, err := r.Reconcile(context.TODO(), req)
Expect(err).ToNot(HaveOccurred())
Expect(result.RequeueAfter).ToNot(BeZero())
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The assertion on line 111 only checks that the Reconcile call doesn't panic, while ignoring the returned error with nolint:errcheck. Since ReconcileInternal is expected to fail in this unit test, a more robust test would be to assert that an error is indeed returned. This makes the test's intent clearer and removes the need for the nolint directive.

Additionally, it's preferable to use context.Background() over context.TODO().

Suggested change
// Reconcile proceeds past getRuntime, builds the engine, then hits the
// "no dataset bound" branch which returns RequeueAfter(5s) with no error.
result, err := r.Reconcile(context.TODO(), req)
Expect(err).ToNot(HaveOccurred())
Expect(result.RequeueAfter).ToNot(BeZero())
// Reconcile will proceed past getRuntime (runtime exists) and call
// ReconcileInternal. We expect an error because ReconcileInternal
// will fail on missing Dataset or other resources in unit-test conditions.
_, err := r.Reconcile(context.Background(), req)
Expect(err).To(HaveOccurred())

Namespace: testNamespace,
},
}
result, err := r.Reconcile(context.TODO(), req)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

It's a good practice to use context.Background() instead of context.TODO() in tests when no specific context is needed. context.Background() is more explicit that this is a root context for a test operation.

Suggested change
result, err := r.Reconcile(context.TODO(), req)
result, err := r.Reconcile(context.Background(), req)

}
r := makeReconciler(s, rt)
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

It's a good practice to use context.Background() instead of context.TODO() in tests when no specific context is needed. This applies to other usages of context.TODO() in this file as well (e.g., lines 91, 114, 129, 142).

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

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 Alluxio controller test suite to Ginkgo v2 and introduces new unit tests, enhancing test coverage for the controller and its implementation. The changes are well-executed. My review includes a suggestion to replace context.TODO() with context.Background() in the new test files to align with Go's best practices for context management.

Namespace: testNamespace,
},
}
result, err := r.Reconcile(context.TODO(), req)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For top-level contexts in tests, context.Background() is preferred over context.TODO(). context.TODO() is a placeholder, while context.Background() is the standard for a root context. Please apply this change to all occurrences of context.TODO() in this file.

Suggested change
result, err := r.Reconcile(context.TODO(), req)
result, err := r.Reconcile(context.Background(), req)

}
r := makeReconciler(s, rt)
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

For top-level contexts in tests, context.Background() is preferred over context.TODO(). context.TODO() is a placeholder, while context.Background() is the standard for a root context. Please apply this change to all occurrences of context.TODO() in this file.

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

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.21%. Comparing base (a69c888) to head (4662d24).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5686   +/-   ##
=======================================
  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.

@hxrshxz hxrshxz force-pushed the test/alluxio-controller-ginkgo-v2 branch from 5886324 to 4f431d2 Compare March 9, 2026 22:21
…roller and implement

- Migrate BeforeSuite to Ginkgo v2 style with NodeTimeout(60s)
- Add unit tests for NewRuntimeReconciler, ControllerName, and Reconcile
- Add unit tests for getRuntime, RemoveEngine, GetOrCreateEngine
- Use context.Background() throughout tests
- Use non-nil MockEngine stub in RemoveEngine test

Signed-off-by: Harsh <harshmastic@gmail.com>
@hxrshxz hxrshxz force-pushed the test/alluxio-controller-ginkgo-v2 branch from e9c794b to 4662d24 Compare March 9, 2026 23:26
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 9, 2026

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