Skip to content

test(nodeaffinitywithcache): migrate Ginkgo/Gomega tests to standard testing with testify#5756

Merged
fluid-e2e-bot[bot] merged 3 commits intofluid-cloudnative:masterfrom
hxrshxz:migrate-nodeaffinitywithcache-tests
Apr 4, 2026
Merged

test(nodeaffinitywithcache): migrate Ginkgo/Gomega tests to standard testing with testify#5756
fluid-e2e-bot[bot] merged 3 commits intofluid-cloudnative:masterfrom
hxrshxz:migrate-nodeaffinitywithcache-tests

Conversation

@hxrshxz
Copy link
Copy Markdown
Contributor

@hxrshxz hxrshxz commented Apr 1, 2026

Ⅰ. Describe what this PR does

Migrate pkg/webhook/plugins/nodeaffinitywithcache/ tests from Ginkgo/Gomega to standard Go testing with testify/assert and testify/require. Removes the Ginkgo suite bootstrap and vendors testify/require.

Ⅱ. Does this pull request fix one issue?

fixes #5676

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

  • node_affinity_with_cache_test.go: converted 5 Ginkgo Describe/It groups (9 specs) to TestNewPluginAndGetName, TestGetPreferredSchedulingTerm, TestMutateOnlyRequired, TestMutateOnlyPrefer, TestMutateBothRequiredAndPrefer, and 4 TestTieredLocality_* functions; extracted repeated YAML locality strings to package-level constants.
  • tiered_locaity_test.go: converted DescribeTable/Entry (4 entries) to TestHasRepeatedLocality with 4 table-driven sub-tests.
  • nodeaffinitywithcache_suite_test.go: deleted (Ginkgo runner bootstrap no longer needed).
  • vendor/github.com/stretchr/testify/require/: vendored testify/require (already declared in go.mod; only assert was previously vendored).

Ⅳ. Describe how to verify it

Run go test ./pkg/webhook/plugins/nodeaffinitywithcache/... -count=1 and confirm all tests pass with no Ginkgo or Gomega imports in the test files. Coverage: 87.2%.

Ⅴ. Special notes for reviews

N/A

Copilot AI review requested due to automatic review settings April 1, 2026 17:17
@hxrshxz
Copy link
Copy Markdown
Contributor Author

hxrshxz commented Apr 1, 2026

/gemini review

Copy link
Copy Markdown
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 migrates the test suite from Ginkgo/Gomega to the standard library's testing package and testify/assert/testify/require libraries. The reviewer suggests optimizing the newTestScheme function by initializing the scheme once as a package-level variable to reduce redundant allocations and recommends removing the assertion on the input map length in TestMutateBothRequiredAndPrefer as it does not test the plugin's mutation logic.

Comment on lines +42 to +48
func newTestScheme(t *testing.T) *runtime.Scheme {
t.Helper()
schema := runtime.NewScheme()
require.NoError(t, datav1alpha1.AddToScheme(schema))
require.NoError(t, corev1.AddToScheme(schema))
return schema
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The newTestScheme function is called in every test case. Since runtime.Scheme is thread-safe for reading after initialization and the scheme used here is static, you could initialize it once as a package-level variable to avoid redundant allocations and setup in every test.

require.NotNil(t, schedPod.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution)
assert.Len(t, schedPod.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms, 1)
assert.Len(t, schedPod.Spec.Affinity.NodeAffinity.PreferredDuringSchedulingIgnoredDuringExecution, 1)
assert.Len(t, runtimeInfos, 2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This assertion checks the length of the input map runtimeInfos. Since Mutate does not modify the input map, this assertion doesn't provide value for testing the plugin's logic. It can be removed to keep the test focused on the mutation results.

Copy link
Copy Markdown
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 nodeaffinitywithcache plugin tests from Ginkgo/Gomega to Go’s standard testing package using testify/assert and testify/require, and removes the Ginkgo suite bootstrap.

Changes:

  • Converted Ginkgo specs/tables to testing.T tests and table-driven subtests with testify.
  • Removed the Ginkgo suite runner (*_suite_test.go).
  • Updated vendoring metadata to include github.com/stretchr/testify/require.

Reviewed changes

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

File Description
vendor/modules.txt Adds testify/require to vendored module package list.
pkg/webhook/plugins/nodeaffinitywithcache/tiered_locaity_test.go Replaces Ginkgo table tests with testing.T + testify table-driven subtests.
pkg/webhook/plugins/nodeaffinitywithcache/nodeaffinitywithcache_suite_test.go Deletes the Ginkgo bootstrap runner.
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go Rewrites multiple Ginkgo suites into standard Go tests and adds shared test helpers/constants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
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 migrates the nodeaffinitywithcache plugin tests from Ginkgo/Gomega to the standard Go testing package using testify/assert and testify/require. The refactoring includes converting existing test suites into standard Go test functions and table-driven tests, alongside updating the vendor directory. Feedback suggests further enhancing the readability and isolation of the new tests by utilizing t.Run subtests instead of manual state resets.

hxrshxz added a commit to hxrshxz/fluid that referenced this pull request Apr 1, 2026
…level var

Replace per-test newTestScheme(t) function with a package-level
testScheme var initialized once via an immediately-invoked function.
This avoids redundant scheme registration on every test invocation.

Addresses Gemini review feedback on PR fluid-cloudnative#5756.

Signed-off-by: Harsh <harshmastic@gmail.com>
@hxrshxz
Copy link
Copy Markdown
Contributor Author

hxrshxz commented Apr 1, 2026

/gemini review

Copy link
Copy Markdown
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 refactors the test suite for the nodeaffinitywithcache plugin, migrating from Ginkgo/Gomega to the standard Go testing package and testify. The review feedback suggests several improvements to the new tests, including handling errors during scheme initialization, refactoring multi-scenario tests into subtests using t.Run for better isolation, and adding missing assertions to verify that no mutations occur in specific edge cases.

Copy link
Copy Markdown
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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

hxrshxz added 2 commits April 1, 2026 23:18
…testing with testify

Signed-off-by: Harsh <harshmastic@gmail.com>
…level var

Replace per-test newTestScheme(t) function with a package-level
testScheme var initialized once via an immediately-invoked function.
This avoids redundant scheme registration on every test invocation.

Addresses Gemini review feedback on PR fluid-cloudnative#5756.

Signed-off-by: Harsh <harshmastic@gmail.com>
@hxrshxz hxrshxz force-pushed the migrate-nodeaffinitywithcache-tests branch from 7003265 to 19df57d Compare April 1, 2026 17:49
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.40%. Comparing base (2f8fc96) to head (9ec9bb0).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5756   +/-   ##
=======================================
  Coverage   61.40%   61.40%           
=======================================
  Files         444      444           
  Lines       30656    30656           
=======================================
  Hits        18824    18824           
  Misses      10285    10285           
  Partials     1547     1547           

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

…cate literals and fix function naming

Signed-off-by: Harsh <harshmastic@gmail.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 1, 2026

@fluid-e2e-bot
Copy link
Copy Markdown

fluid-e2e-bot bot commented Apr 3, 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.

@cheyang
Copy link
Copy Markdown
Collaborator

cheyang commented Apr 4, 2026

/ok-to-test

@cheyang
Copy link
Copy Markdown
Collaborator

cheyang commented Apr 4, 2026

Non-blocking comment: this migration looks solid overall. A small follow-up improvement would be to strengthen a few of the converted tests so they assert the resulting affinity structure more directly, not just the no-error path. I do not see this as a blocker for the current PR.

@cheyang
Copy link
Copy Markdown
Collaborator

cheyang commented Apr 4, 2026

/lgtm

Copy link
Copy Markdown
Collaborator

@cheyang cheyang left a comment

Choose a reason for hiding this comment

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

/approve

@fluid-e2e-bot
Copy link
Copy Markdown

fluid-e2e-bot bot commented Apr 4, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cheyang

The full list of commands accepted by this bot can be found here.

The pull request process is described 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 fluid-e2e-bot bot merged commit 9fe6aad into fluid-cloudnative:master Apr 4, 2026
18 checks passed
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.

Unify and Modernize Fluid’s Unit Testing Framework and Enhance Testing Coverage

3 participants