Skip to content

test(dataflowaffinity): migrate to Ginkgo/Gomega#5685

Open
hxrshxz wants to merge 2 commits intofluid-cloudnative:masterfrom
hxrshxz:test/dataflowaffinity-ginkgo
Open

test(dataflowaffinity): migrate to Ginkgo/Gomega#5685
hxrshxz wants to merge 2 commits intofluid-cloudnative:masterfrom
hxrshxz:test/dataflowaffinity-ginkgo

Conversation

@hxrshxz
Copy link
Contributor

@hxrshxz hxrshxz commented Mar 9, 2026

Ⅰ. Describe what this PR does

Migrates unit tests in pkg/controllers/v1alpha1/fluidapp/dataflowaffinity/ from the standard testing package to Ginkgo v2/Gomega, adds a package-level suite bootstrap (suite_test.go), and expands test coverage from 39% to 81.4% by adding specs for Reconcile, ControllerName, ManagedResource, and NewDataOpJobReconciler.

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

  • ControllerName — asserts the constant string is returned
  • ManagedResource — asserts a *batchv1.Job is returned
  • NewDataOpJobReconciler — asserts the constructor wires client correctly
  • Reconcile (4 cases): job not found (propagates error), job with cronjob label (skipped/no-requeue), valid fluid job without affinity annotation (annotation injected), complete job with succeeded pod (node labels injected)
  • injectPodNodeLabelsToJob (2 cases): succeeded pod injects annotations; failed-only pod returns error

Ⅳ. Describe how to verify it

go test ./pkg/controllers/v1alpha1/fluidapp/dataflowaffinity/... -v -count=1
go test ./pkg/controllers/v1alpha1/fluidapp/dataflowaffinity/... -coverprofile=/tmp/c.out -covermode=atomic && go tool cover -func=/tmp/c.out | grep total

Ⅴ. Special notes for reviews

N/A

Copilot AI review requested due to automatic review settings March 9, 2026 16:43
@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 ronggu for approval by writing /assign @ronggu 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 testing quality and coverage for the dataflowaffinity controller. It modernizes the testing infrastructure by migrating existing unit tests to the Ginkgo/Gomega framework and introduces a suite of new, detailed test cases that validate critical controller functionalities, thereby improving the robustness and reliability of the component.

Highlights

  • Testing Framework Migration: Migrated unit tests in pkg/controllers/v1alpha1/fluidapp/dataflowaffinity/ from the standard testing package to Ginkgo v2/Gomega.
  • Test Suite Bootstrap: Added a package-level suite bootstrap (suite_test.go) for the new testing framework.
  • Test Coverage Expansion: Expanded test coverage from 39% to 81.4% by introducing new specs.
  • New Test Cases: Added comprehensive test cases for Reconcile (covering job not found, cronjob labels, affinity annotation injection, and node label injection), ControllerName, ManagedResource, and NewDataOpJobReconciler.
Changelog
  • pkg/controllers/v1alpha1/fluidapp/dataflowaffinity/dataflowaffinity_controller_test.go
    • Rewrote existing injectPodNodeLabelsToJob tests to use Ginkgo/Gomega syntax.
    • Introduced new Describe blocks and It statements for ControllerName, ManagedResource, NewDataOpJobReconciler, and Reconcile functions.
    • Added specific test contexts for Reconcile covering scenarios like non-existent jobs, jobs with cronjob labels, fluid jobs without affinity annotations, and complete jobs with succeeded pods.
    • Updated injectPodNodeLabelsToJob tests to include contexts for succeeded and failed pods.
  • pkg/controllers/v1alpha1/fluidapp/dataflowaffinity/suite_test.go
    • Created a new file to set up the Ginkgo test suite, including RegisterFailHandler and RunSpecs for the Dataflowaffinity Suite.
Activity
  • No specific human activity (comments, reviews, progress) has been recorded for 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.

Signed-off-by: Harsh <harshmastic@gmail.com>
@hxrshxz hxrshxz force-pushed the test/dataflowaffinity-ginkgo branch from 320340a to 4fe7d5b Compare March 9, 2026 16:44
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

The pull request refactors the dataflowaffinity_controller_test.go file from the standard testing package to use the Ginkgo/Gomega testing framework, introducing a new suite_test.go file for test setup. This includes comprehensive test cases for the DataOpJobReconciler's Reconcile method and the injectPodNodeLabelsToJob helper function. A review comment suggests replacing context.TODO() with context.Background() in the tests for improved clarity and adherence to best practices.

It("returns an error (not-found propagates)", func() {
c := fake.NewFakeClientWithScheme(testScheme)
f := &DataOpJobReconciler{Client: c, Log: fake.NullLogger()}
_, err := f.Reconcile(context.TODO(), reconcile.Request{
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 is a better practice to use context.Background() instead of context.TODO() in tests when a background, non-cancellable context is needed. context.TODO() is intended as a temporary placeholder. Please replace all instances of context.TODO() with context.Background() in this file for consistency and clarity.

Suggested change
_, err := f.Reconcile(context.TODO(), reconcile.Request{
_, err := f.Reconcile(context.Background(), reconcile.Request{

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

This PR migrates the unit tests in pkg/controllers/v1alpha1/fluidapp/dataflowaffinity/ from Go's standard testing package table-driven style to Ginkgo v2/Gomega BDD-style, adds a suite bootstrap file, and expands test coverage from 39% to 81.4% by adding specs for Reconcile, ControllerName, ManagedResource, and NewDataOpJobReconciler.

Changes:

  • Added suite_test.go to bootstrap the Ginkgo test suite for the dataflowaffinity package.
  • Migrated existing injectPodNodeLabelsToJob tests from table-driven testing.T style to Ginkgo Describe/Context/It blocks.
  • Added new test specs covering ControllerName, ManagedResource, NewDataOpJobReconciler, and four Reconcile scenarios (not-found, cronjob-skip, annotation injection, complete-job with node label injection).

Reviewed changes

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

File Description
pkg/controllers/v1alpha1/fluidapp/dataflowaffinity/suite_test.go New Ginkgo suite bootstrap file for the dataflowaffinity package
pkg/controllers/v1alpha1/fluidapp/dataflowaffinity/dataflowaffinity_controller_test.go Migrated existing tests to Ginkgo/Gomega and added new test specs for broader coverage

💡 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
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 (46458b8).

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

Signed-off-by: Harsh <harshmastic@gmail.com>
@hxrshxz hxrshxz force-pushed the test/dataflowaffinity-ginkgo branch from 0ea9958 to 46458b8 Compare March 9, 2026 21:15
@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