-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Migrate (pkg/ddc/juicefs/health_check_test.go) tests to use Ginkgo #5531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Migrate (pkg/ddc/juicefs/health_check_test.go) tests to use Ginkgo #5531
Conversation
Signed-off-by: Harsh <harshmastic@gmail.com>
Summary of ChangesHello @hxrshxz, 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 modernizes the testing infrastructure for the JuiceFS health check logic by migrating existing tests to the Ginkgo/Gomega framework. This change improves the clarity, structure, and maintainability of the test suite, making it easier to understand test intent and outcomes. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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
|
|
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. |
There was a problem hiding this 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 tests in pkg/ddc/juicefs/health_check_test.go to use the Ginkgo/Gomega framework, which improves test readability and structure. The conversion from table-driven tests to individual It blocks with BeforeEach setup is well-executed. I have one suggestion to improve consistency in the test setup code.
pkg/ddc/juicefs/health_check_test.go
Outdated
| engines = []JuiceFSEngine{ | ||
| { | ||
| Client: fakeClient, | ||
| Log: fake.NullLogger(), | ||
| namespace: "fluid", | ||
| name: "hbase", | ||
| runtime: &datav1alpha1.JuiceFSRuntime{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "hbase", | ||
| Namespace: "fluid", | ||
| }, | ||
| }, | ||
| Recorder: record.NewFakeRecorder(1), | ||
| }, | ||
| { | ||
| Client: fakeClient, | ||
| Log: fake.NullLogger(), | ||
| namespace: "fluid", | ||
| name: "spark", | ||
| runtime: &datav1alpha1.JuiceFSRuntime{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "spark", | ||
| Namespace: "fluid", | ||
| }, | ||
| }, | ||
| Recorder: record.NewFakeRecorder(1), | ||
| }, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency and to reduce redundancy, consider reusing the juicefsruntimeInputs slice when initializing the engines, similar to how it's done in the CheckRuntimeHealthy test suite. This makes the test setup cleaner and easier to maintain.
engines = []JuiceFSEngine{
{
Client: fakeClient,
Log: fake.NullLogger(),
namespace: "fluid",
name: "hbase",
runtime: &juicefsruntimeInputs[0],
Recorder: record.NewFakeRecorder(1),
},
{
Client: fakeClient,
Log: fake.NullLogger(),
namespace: "fluid",
name: "spark",
runtime: &juicefsruntimeInputs[1],
Recorder: record.NewFakeRecorder(1),
},
}
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5531 +/- ##
=======================================
Coverage 61.30% 61.30%
=======================================
Files 444 444
Lines 30540 30540
=======================================
Hits 18723 18723
Misses 10275 10275
Partials 1542 1542 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/gemini review |
1 similar comment
|
/gemini review |
There was a problem hiding this 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 tests in pkg/ddc/juicefs/health_check_test.go from the standard Go testing framework to Ginkgo and Gomega. The refactoring improves test structure and readability by using Describe/It blocks and BeforeEach for setup. The logic of the original table-driven tests is preserved. I've suggested one improvement to make a test assertion more robust by avoiding reliance on the order of items returned from a list call, which can be flaky.
pkg/ddc/juicefs/health_check_test.go
Outdated
| var datasets datav1alpha1.DatasetList | ||
| err = fakeClient.List(context.TODO(), &datasets) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(datasets.Items[0].Status.Phase).To(Equal(datav1alpha1.BoundDatasetPhase)) | ||
| Expect(datasets.Items[0].Status.CacheStates).To(BeEquivalentTo(map[common.CacheStateName]string{ | ||
| common.Cached: "true", | ||
| })) | ||
| Expect(datasets.Items[0].Status.HCFSStatus).To(Equal(&datav1alpha1.HCFSStatus{ | ||
| Endpoint: "test Endpoint", | ||
| UnderlayerFileSystemVersion: "Underlayer HCFS Compatible Version", | ||
| })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on client.List and then accessing datasets.Items[0] can lead to flaky tests, as the order of items returned by the fake client's List method is not guaranteed. It's more robust to fetch the specific Dataset object by its name and namespace using client.Get.
| var datasets datav1alpha1.DatasetList | |
| err = fakeClient.List(context.TODO(), &datasets) | |
| Expect(err).NotTo(HaveOccurred()) | |
| Expect(datasets.Items[0].Status.Phase).To(Equal(datav1alpha1.BoundDatasetPhase)) | |
| Expect(datasets.Items[0].Status.CacheStates).To(BeEquivalentTo(map[common.CacheStateName]string{ | |
| common.Cached: "true", | |
| })) | |
| Expect(datasets.Items[0].Status.HCFSStatus).To(Equal(&datav1alpha1.HCFSStatus{ | |
| Endpoint: "test Endpoint", | |
| UnderlayerFileSystemVersion: "Underlayer HCFS Compatible Version", | |
| })) | |
| var dataset datav1alpha1.Dataset | |
| err = fakeClient.Get(context.TODO(), client.ObjectKey{Name: "hbase", Namespace: "fluid"}, &dataset) | |
| Expect(err).NotTo(HaveOccurred()) | |
| Expect(dataset.Status.Phase).To(Equal(datav1alpha1.BoundDatasetPhase)) | |
| Expect(dataset.Status.CacheStates).To(BeEquivalentTo(map[common.CacheStateName]string{ | |
| common.Cached: "true", | |
| })) | |
| Expect(dataset.Status.HCFSStatus).To(Equal(&datav1alpha1.HCFSStatus{ | |
| Endpoint: "test Endpoint", | |
| UnderlayerFileSystemVersion: "Underlayer HCFS Compatible Version", | |
| })) |
There was a problem hiding this 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 tests in pkg/ddc/juicefs/health_check_test.go from the standard Go testing framework to Ginkgo/Gomega. The conversion from table-driven tests to individual It blocks with BeforeEach setup improves test readability and isolation. The assertions are correctly updated to use Gomega matchers.
I've added one suggestion to improve the robustness of a test by fetching a resource directly by name instead of relying on its index in a list, which can be unstable.
pkg/ddc/juicefs/health_check_test.go
Outdated
| var datasets datav1alpha1.DatasetList | ||
| err = fakeClient.List(context.TODO(), &datasets) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(datasets.Items[0].Status.Phase).To(Equal(datav1alpha1.BoundDatasetPhase)) | ||
| Expect(datasets.Items[0].Status.CacheStates).To(BeEquivalentTo(map[common.CacheStateName]string{ | ||
| common.Cached: "true", | ||
| })) | ||
| Expect(datasets.Items[0].Status.HCFSStatus).To(Equal(&datav1alpha1.HCFSStatus{ | ||
| Endpoint: "test Endpoint", | ||
| UnderlayerFileSystemVersion: "Underlayer HCFS Compatible Version", | ||
| })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on the order of items from fakeClient.List can make tests brittle, as the order is not guaranteed. It's more robust to fetch the specific Dataset object by name to ensure assertions are made against the correct object.
Also, it's a good practice to use context.Background() instead of context.TODO() in tests when a specific context isn't required.
| var datasets datav1alpha1.DatasetList | |
| err = fakeClient.List(context.TODO(), &datasets) | |
| Expect(err).NotTo(HaveOccurred()) | |
| Expect(datasets.Items[0].Status.Phase).To(Equal(datav1alpha1.BoundDatasetPhase)) | |
| Expect(datasets.Items[0].Status.CacheStates).To(BeEquivalentTo(map[common.CacheStateName]string{ | |
| common.Cached: "true", | |
| })) | |
| Expect(datasets.Items[0].Status.HCFSStatus).To(Equal(&datav1alpha1.HCFSStatus{ | |
| Endpoint: "test Endpoint", | |
| UnderlayerFileSystemVersion: "Underlayer HCFS Compatible Version", | |
| })) | |
| var hbaseDataset datav1alpha1.Dataset | |
| err = fakeClient.Get(context.Background(), client.ObjectKey{Name: "hbase", Namespace: "fluid"}, &hbaseDataset) | |
| Expect(err).NotTo(HaveOccurred()) | |
| Expect(hbaseDataset.Status.Phase).To(Equal(datav1alpha1.BoundDatasetPhase)) | |
| Expect(hbaseDataset.Status.CacheStates).To(BeEquivalentTo(map[common.CacheStateName]string{ | |
| common.Cached: "true", | |
| })) | |
| Expect(hbaseDataset.Status.HCFSStatus).To(Equal(&datav1alpha1.HCFSStatus{ | |
| Endpoint: "test Endpoint", | |
| UnderlayerFileSystemVersion: "Underlayer HCFS Compatible Version", | |
| })) |
Signed-off-by: Harsh <harshmastic@gmail.com>
There was a problem hiding this 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 test file pkg/ddc/juicefs/health_check_test.go from the standard Go testing framework to Ginkgo v2 and Gomega, aligning with the project's goal (issue #5407) to standardize testing practices and improve test readability and maintainability.
Changes:
- Migrated two test functions (
TestCheckRuntimeHealthyandTestCheckFuseHealthy) to Ginkgo-style Describe blocks with BDD-style test organization - Replaced standard Go testing assertions with Gomega matchers for more expressive test expectations
- Updated package declaration in
juicefs_suite_test.gofromjuicefs_testtojuicefsfor consistency with other test files in the package
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/ddc/juicefs/juicefs_suite_test.go | Changed package declaration from juicefs_test to juicefs to align with codebase conventions |
| pkg/ddc/juicefs/health_check_test.go | Migrated test functions to Ginkgo/Gomega framework, converted table-driven tests to individual It blocks with BeforeEach setup, replaced all assertions with Gomega matchers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…alth-check # Conflicts: # pkg/ddc/juicefs/health_check_test.go
|
[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 |
|



Summary
Ⅰ. Migrate
pkg/ddc/juicefs/health_check_test.gofrom standard Go testing to Ginkgo/Gomega frameworkⅡ. Convert table-driven tests to individual It() blocks with BeforeEach setup
Ⅲ. Replace all t.Errorf assertions with Gomega matchers (Expect/To/Equal/BeEquivalentTo)
Ⅳ. Update imports to use Ginkgo v2 and Gomega
Ⅴ. Part of #5407
Changes
testingpackage, added Ginkgo/Gomega importsTestCheckRuntimeHealthy,TestCheckFuseHealthy) to Describe blocksTesting