test(nodeaffinitywithcache): migrate Ginkgo/Gomega tests to standard testing with testify#5756
Conversation
|
/gemini review |
There was a problem hiding this comment.
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.
| 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 | ||
| } |
There was a problem hiding this comment.
| 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) |
There was a problem hiding this comment.
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.Ttests and table-driven subtests withtestify. - 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.
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go
Show resolved
Hide resolved
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go
Show resolved
Hide resolved
…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>
|
/gemini review |
There was a problem hiding this comment.
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.
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go
Show resolved
Hide resolved
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go
Show resolved
Hide resolved
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go
Show resolved
Hide resolved
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go
Show resolved
Hide resolved
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go
Show resolved
Hide resolved
There was a problem hiding this comment.
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.
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go
Show resolved
Hide resolved
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go
Show resolved
Hide resolved
pkg/webhook/plugins/nodeaffinitywithcache/node_affinity_with_cache_test.go
Show resolved
Hide resolved
…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>
7003265 to
19df57d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
…cate literals and fix function naming Signed-off-by: Harsh <harshmastic@gmail.com>
|
|
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. |
|
/ok-to-test |
|
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. |
|
/lgtm |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |



Ⅰ. Describe what this PR does
Migrate
pkg/webhook/plugins/nodeaffinitywithcache/tests from Ginkgo/Gomega to standard Gotestingwithtestify/assertandtestify/require. Removes the Ginkgo suite bootstrap and vendorstestify/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 GinkgoDescribe/Itgroups (9 specs) toTestNewPluginAndGetName,TestGetPreferredSchedulingTerm,TestMutateOnlyRequired,TestMutateOnlyPrefer,TestMutateBothRequiredAndPrefer, and 4TestTieredLocality_*functions; extracted repeated YAML locality strings to package-level constants.tiered_locaity_test.go: convertedDescribeTable/Entry(4 entries) toTestHasRepeatedLocalitywith 4 table-driven sub-tests.nodeaffinitywithcache_suite_test.go: deleted (Ginkgo runner bootstrap no longer needed).vendor/github.com/stretchr/testify/require/: vendoredtestify/require(already declared ingo.mod; onlyassertwas previously vendored).Ⅳ. Describe how to verify it
Run
go test ./pkg/webhook/plugins/nodeaffinitywithcache/... -count=1and confirm all tests pass with no Ginkgo or Gomega imports in the test files. Coverage: 87.2%.Ⅴ. Special notes for reviews
N/A