-
Notifications
You must be signed in to change notification settings - Fork 1.1k
test: migrate container tests from testify to ginkgo #5429
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?
test: migrate container tests from testify to ginkgo #5429
Conversation
Signed-off-by: Yuvraj Kolkar <[email protected]>
|
[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 of ChangesHello @yuvraj-kolkar17, 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 focuses on modernizing the testing infrastructure for the 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 @yuvraj-kolkar17. 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 container tests from testify to ginkgo, which improves the readability and structure of the tests. The addition of new test cases for multiple sidecars and error handling is a valuable improvement.
However, there are a couple of critical issues that will prevent the code from compiling. The new mock object mockFluidObject does not fully implement the common.FluidObject interface, and several necessary packages (errors, runtime, metav1) are not imported. My review includes suggestions to fix these issues.
| // mockFluidObject is a mock implementation of common.FluidObject for testing error handling | ||
| type mockFluidObject struct { | ||
| shouldError bool | ||
| containers []corev1.Container | ||
| } | ||
|
|
||
| func (m *mockFluidObject) GetContainers() ([]corev1.Container, error) { | ||
| if m.shouldError { | ||
| return nil, ErrMockGetContainers | ||
| } | ||
| return m.containers, nil | ||
| } | ||
|
|
||
| // Implement other required methods from common.FluidObject interface | ||
| // (these are placeholders and should be adjusted based on the actual interface) | ||
| func (m *mockFluidObject) GetName() string { | ||
| return "mock-pod" | ||
| } | ||
|
|
||
| func (m *mockFluidObject) GetNamespace() string { | ||
| return "default" | ||
| } |
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.
The mockFluidObject does not fully implement the common.FluidObject interface, which will cause a compilation error. To fix this, all methods of the interface must be implemented.
Additionally, the GetName and GetNamespace methods are not part of the common.FluidObject interface and should be removed to avoid confusion.
Note that to implement the interface correctly, you will also need to add the following imports:
import (
// ... other imports
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)// mockFluidObject is a mock implementation of common.FluidObject for testing error handling
type mockFluidObject struct {
shouldError bool
containers []corev1.Container
}
func (m *mockFluidObject) GetContainers() ([]corev1.Container, error) {
if m.shouldError {
return nil, ErrMockGetContainers
}
return m.containers, nil
}
// The following methods are added to fully implement the common.FluidObject interface.
func (m *mockFluidObject) GetRoot() runtime.Object { return nil }
func (m *mockFluidObject) GetVolumes() ([]corev1.Volume, error) { return nil, nil }
func (m *mockFluidObject) SetVolumes(volumes []corev1.Volume) error { return nil }
func (m *mockFluidObject) GetInitContainers() ([]corev1.Container, error) { return nil, nil }
func (m *mockFluidObject) SetContainers(containers []corev1.Container) error { return nil }
func (m *mockFluidObject) SetInitContainers(containers []corev1.Container) error { return nil }
func (m *mockFluidObject) GetVolumeMounts() ([]corev1.VolumeMount, error) { return nil, nil }
func (m *mockFluidObject) SetMetaObject(metaObject metav1.ObjectMeta) error { return nil }
func (m *mockFluidObject) GetMetaObject() (metav1.ObjectMeta, error) { return metav1.ObjectMeta{}, nil }| return "default" | ||
| } | ||
|
|
||
| var ErrMockGetContainers = errors.New("mock error from GetContainers") |
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.
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
The pull request successfully migrates the container tests from testify to ginkgo and gomega. This significantly improves the test structure and readability, making it easier to understand and maintain the test suite. The addition of new test cases for multiple injected sidecars and error handling from GetContainers also enhances the overall test coverage and robustness. The use of a mockFluidObject for error testing is a good practice.
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" |
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.
The errors package is used for errors.New on line 145, but it's not imported. Please add the errors package to the import list to resolve the compilation error.
| . "github.com/onsi/ginkgo/v2" | |
| . "github.com/onsi/gomega" | |
| "errors" | |
| . "github.com/onsi/ginkgo/v2" | |
| . "github.com/onsi/gomega" |
Signed-off-by: Yuvraj Kolkar <[email protected]>
|



Ⅰ. Describe what this PR does
What this PR does
Changes:
Replaced table-driven tests with Ginkgo Describe/Context/It blocks
Replaced testify assertions with Gomega matchers
Added mock implementation of FluidObject to test error handling
Improved test case naming for better clarity
Ⅱ. Does this pull request fix one issue?
fixes #5407
Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.
Added test cases:
"when pod has no injected sidecars" - verifies empty slice is returned (existing)
"when pod has one injected sidecar" - verifies single FUSE container detection (existing)
"when pod has multiple injected sidecars" - verifies multiple FUSE containers are detected (new)
"when GetContainers returns an error" - verifies error handling path, covers previously uncovered lines 29-31 (new)
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews