-
Notifications
You must be signed in to change notification settings - Fork 2
test: add pods and descriptions dump #1519
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
Conversation
This is required to get more information about the state of test case resources when a test fails. Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
Reviewer's GuideThis PR refactors the test failure dump mechanism by renaming and splitting the original SaveTestResources function into a new SaveTestCaseDump wrapper with dedicated helpers for resource, log, and description dumps (including namespace support), and updates all e2e tests to use the new API. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey there - I've reviewed your changes - here's some feedback:
- Consider creating the dumpPath directory if it doesn’t already exist before writing files to avoid write failures.
- There’s a lot of duplicated logic in SavePodLogs and SavePodDescriptions—extract the common pod iteration and file-writing code into a helper to reduce repetition.
- Inside the loops, error logging refers to the wrong variable (err) when cmd.Error occurs; make sure you’re printing the actual command error (cmd.Error()).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider creating the dumpPath directory if it doesn’t already exist before writing files to avoid write failures.
- There’s a lot of duplicated logic in SavePodLogs and SavePodDescriptions—extract the common pod iteration and file-writing code into a helper to reduce repetition.
- Inside the loops, error logging refers to the wrong variable (err) when cmd.Error occurs; make sure you’re printing the actual command error (cmd.Error()).
## Individual Comments
### Comment 1
<location> `tests/e2e/util_test.go:796` </location>
<code_context>
+ pods := &corev1.PodList{}
+ err := GetObjects(kc.ResourcePod, pods, kc.GetOptions{Namespace: namespace, Labels: labels})
+ if err != nil {
+ GinkgoWriter.Printf("Failed to get PodList:\n%s\n", err)
+ }
+
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding a test for handling empty pod lists in SavePodLogs and SavePodDescriptions.
A test verifying the behavior when the pod list is empty will clarify expectations and aid future maintenance.
Suggested implementation:
```golang
import (
"testing"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
)
func TestSavePodLogs_EmptyPodList(t *testing.T) {
// Arrange
labels := map[string]string{"app": "test"}
additional := "additional"
namespace := "default"
dumpPath := "/tmp"
// Mock GetObjects to return an empty pod list
originalGetObjects := GetObjects
defer func() { GetObjects = originalGetObjects }()
GetObjects = func(resource string, obj interface{}, opts kc.GetOptions) error {
podList, ok := obj.(*corev1.PodList)
if ok {
podList.Items = []corev1.Pod{}
}
return nil
}
// Act
SavePodLogs(labels, additional, namespace, dumpPath)
// Assert
// No panic or error expected, logs should indicate empty pod list handled gracefully
// (You may want to check log output if your framework supports it)
}
func TestSavePodDescriptions_EmptyPodList(t *testing.T) {
// Arrange
labels := map[string]string{"app": "test"}
additional := "additional"
namespace := "default"
dumpPath := "/tmp"
// Mock GetObjects to return an empty pod list
originalGetObjects := GetObjects
defer func() { GetObjects = originalGetObjects }()
GetObjects = func(resource string, obj interface{}, opts kc.GetOptions) error {
podList, ok := obj.(*corev1.PodList)
if ok {
podList.Items = []corev1.Pod{}
}
return nil
}
// Act
SavePodDescriptions(labels, additional, namespace, dumpPath)
// Assert
// No panic or error expected, logs should indicate empty pod list handled gracefully
// (You may want to check log output if your framework supports it)
}
```
- If `SavePodDescriptions` does not exist or has a different signature, adjust the test accordingly.
- If you use a different mocking framework, adapt the mocking of `GetObjects` to your project's conventions.
- If your test suite uses Ginkgo or another BDD framework, you may want to use its test constructs instead of the standard `testing` package.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
af6f447
to
ea1dd02
Compare
Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
Workflow has started. The target step completed with status: failure. |
This is required to get more information about the state of test case resources when a test fails. Signed-off-by: Roman Sysoev <roman.sysoev@flant.com> (cherry picked from commit 0ed00cf)
Description
Why do we need it, and what problem does it solve?
This is required to get more information about the state of test case resources when a test fails.
What is the expected result?
Checklist
Changelog entries