test(dataset): migrate dataset controller tests to Ginkgo v2#5683
test(dataset): migrate dataset controller tests to Ginkgo v2#5683hxrshxz wants to merge 3 commits intofluid-cloudnative:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
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 Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
Summary of ChangesHello, 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 robustness of the dataset controller. It upgrades the testing framework to Ginkgo v2, introduces a lazy and thread-safe mechanism for runtime precheck discovery, and substantially expands unit test coverage for core reconciliation and deletion logic, ensuring greater stability and reliability. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request successfully migrates the dataset controller tests to Ginkgo v2, significantly increasing unit test coverage for the dataset reconciler. It also introduces a lazy initialization mechanism for runtime precheck functions to prevent failures during package initialization in tests. My review includes a suggestion to improve the performance of this new lazy loading mechanism by caching the resolved functions.
There was a problem hiding this comment.
Pull request overview
Migrates the dataset controller test suite to Ginkgo v2, adds unit tests for dataset reconcile/deletion behaviors, and refactors runtime-controller precheck registration to be lazily resolved to avoid package-init failures.
Changes:
- Added fake-client unit tests for
DatasetReconcilercovering finalizer, phase transitions, reference-dataset handling, and deletion flows. - Updated dataset envtest suite bootstrap to Ginkgo v2 and added an explicit opt-in env var to skip envtest start failures.
- Refactored deploy runtime-controller precheck function handling to be lazy/clonable and added tests for lazy resolution + injected prechecks.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/controllers/v1alpha1/dataset/suite_test_helpers_test.go | Adds unit test coverage for the envtest-skip gating helper. |
| pkg/controllers/v1alpha1/dataset/suite_test.go | Migrates suite setup to Ginkgo v2 and makes envtest start failure skippable via env var. |
| pkg/controllers/v1alpha1/dataset/dataset_reconciler_test.go | Adds fake-client unit coverage for dataset reconcile and deletion behaviors. |
| pkg/controllers/deploy/runtime_controllers_test.go | Adds tests for lazy precheck resolution and injected prechecks; updates existing expectations/env setup. |
| pkg/controllers/deploy/runtime_controllers.go | Makes runtime precheck discovery lazy and concurrency-safe with cloning. |
💡 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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5683 +/- ##
=======================================
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. 🚀 New features to boost your workflow:
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request is a significant improvement to the test suite. It successfully migrates the dataset controller tests to Ginkgo v2, substantially increases unit test coverage with well-designed test cases, and refactors the runtime precheck discovery to be lazy, which resolves test initialization issues. The code is well-structured and the new tests are thorough. I have one minor suggestion to make a test assertion more explicit.
| getErr := r.Get(ctx, types.NamespacedName{Namespace: "default", Name: "del-clean"}, stored) | ||
| // Either the object is deleted (not found) or it exists without the finalizer | ||
| if getErr == nil { | ||
| Expect(stored.Finalizers).NotTo(ContainElement(finalizer)) | ||
| } |
There was a problem hiding this comment.
The check for object deletion could be more explicit. When the finalizer is removed from an object that has a deletion timestamp, the object should be garbage collected. The fake client from controller-runtime simulates this behavior, so r.Get should return a NotFound error. It would be better to assert this directly to make the test's intent clearer and more robust.
You will need to import k8s.io/apimachinery/pkg/api/errors as apierrors.
| getErr := r.Get(ctx, types.NamespacedName{Namespace: "default", Name: "del-clean"}, stored) | |
| // Either the object is deleted (not found) or it exists without the finalizer | |
| if getErr == nil { | |
| Expect(stored.Finalizers).NotTo(ContainElement(finalizer)) | |
| } | |
| getErr := r.Get(ctx, types.NamespacedName{Namespace: "default", Name: "del-clean"}, stored) | |
| Expect(apierrors.IsNotFound(getErr)).To(BeTrue()) |
There was a problem hiding this comment.
Fixed in 1db717d8. The deletion-path test now asserts an explicit NotFound result from the fake client after finalizer removal instead of allowing either outcome.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 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.
|
|
||
| stored := &datav1alpha1.Dataset{} | ||
| getErr := r.Get(ctx, types.NamespacedName{Namespace: "default", Name: "del-clean"}, stored) | ||
| Expect(apierrors.IsNotFound(getErr)).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("requeues when DatasetRef still has live entries", func() { | ||
| now := metav1.Now() | ||
| // Create both the main dataset and the referenced dataset in the fake store. |
There was a problem hiding this comment.
In this test, getErr is only checked for nil, and any non-nil error (including unexpected ones) will silently pass the assertion. Also, the comment claims the fake client will delete the object after finalizer removal, but controller-runtime's fake client does not emulate GC deletion. Please assert getErr is either nil or apierrors.IsNotFound(getErr), and adjust the comment accordingly (or simply verify the stored object has the finalizer removed when getErr == nil).
| @@ -210,6 +329,14 @@ func Test_scaleoutDeploymentIfNeeded(t *testing.T) { | |||
| } | |||
|
|
|||
| func TestScaleoutRuntimeContollerOnDemand(t *testing.T) { | |||
There was a problem hiding this comment.
Typo in test name: TestScaleoutRuntimeContollerOnDemand should be TestScaleoutRuntimeControllerOnDemand for consistency and searchability.
| func TestScaleoutRuntimeContollerOnDemand(t *testing.T) { | |
| func TestScaleoutRuntimeControllerOnDemand(t *testing.T) { |
|



Ⅰ. Describe what this PR does
Migrates
pkg/controllers/v1alpha1/datasettests to Ginkgo v2, adds dataset controller unit coverage, and makes runtime precheck discovery lazy so the dataset package tests do not fail during package initialization.Ⅱ. 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 unit tests for:
ControllerNameaddFinalizerAndRequeuesuccess and update error pathsreconcileDatasetinvalid name, finalizer add, phase transition, requeue behavior, deletion delegation, reference dataset validation, thin runtime creation, thin runtime create error, and status update errorreconcileDatasetDeletionclean delete, liveDatasetRefrequeue, staleDatasetRefpruning, PVC/pod deletion blocking, finalizer removal update error, and datasetRef status update errorRetained the existing envtest-backed dataset creation spec and updated the suite bootstrap to Ginkgo v2 semantics.
Ⅳ. Describe how to verify it
Run:
If you want the envtest-backed dataset spec to run as well, use working envtest assets:
KUBEBUILDER_ASSETS=/home/hxrshxz/.local/share/kubebuilder-envtest/k8s/1.29.4-linux-amd64 go test -v ./pkg/controllers/v1alpha1/dataset/...Ⅴ. Special notes for reviews
N/A