Skip to content

Conversation

hardcoretime
Copy link
Contributor

@hardcoretime hardcoretime commented Oct 1, 2025

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

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

section: api
type: chore
summary: "Pods and descriptions will be saved when a test fails."
impact_level: low

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>
@hardcoretime hardcoretime requested a review from danilrwx as a code owner October 1, 2025 20:00
Copy link

sourcery-ai bot commented Oct 1, 2025

Reviewer's Guide

This 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

Change Details Files
Refactor and split the test dump utility
  • Renamed SaveTestResources to SaveTestCaseDump and updated its signature to include namespace
  • Extracted resource dumping into SaveTestCaseResources with updated kubectl.Get options
  • Added SavePodLogs and SavePodDescriptions to capture pod logs and describe output
tests/e2e/util_test.go
Update e2e tests to invoke the new dump function
  • Replaced all SaveTestResources calls with SaveTestCaseDump
  • Passed the appropriate namespace argument to SaveTestCaseDump in AfterEach hooks
tests/e2e/affinity_toleration_test.go
tests/e2e/complex_test.go
tests/e2e/image_hotplug_test.go
tests/e2e/images_creation_test.go
tests/e2e/importer_network_policy_test.go
tests/e2e/sizing_policy_test.go
tests/e2e/vd_snapshots_test.go
tests/e2e/vm_configuration_test.go
tests/e2e/vm_connectivity_test.go
tests/e2e/vm_disk_attachment_test.go
tests/e2e/vm_disk_resizing_test.go
tests/e2e/vm_evacuation_test.go
tests/e2e/vm_label_annotation_test.go
tests/e2e/vm_migration_cancel_test.go
tests/e2e/vm_migration_test.go
tests/e2e/vm_restore_force_test.go
tests/e2e/vm_restore_safe_test.go
tests/e2e/vm_version_test.go
tests/e2e/vm_vpc_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a 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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@hardcoretime hardcoretime added this to the v1.1.0 milestone Oct 1, 2025
Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
@hardcoretime hardcoretime force-pushed the test/add-pods-and-descriptions-dump branch from af6f447 to ea1dd02 Compare October 1, 2025 20:19
Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
@hardcoretime hardcoretime merged commit 0ed00cf into main Oct 2, 2025
27 of 28 checks passed
@hardcoretime hardcoretime deleted the test/add-pods-and-descriptions-dump branch October 2, 2025 11:12
@hardcoretime hardcoretime added the e2e/run Run e2e test on cluster of PR author label Oct 2, 2025
@deckhouse-BOaTswain
Copy link
Contributor

deckhouse-BOaTswain commented Oct 2, 2025

Workflow has started.
Follow the progress here: Workflow Run

The target step completed with status: failure.

@deckhouse-BOaTswain deckhouse-BOaTswain removed the e2e/run Run e2e test on cluster of PR author label Oct 2, 2025
Isteb4k pushed a commit that referenced this pull request Oct 3, 2025
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants