@@ -17,6 +17,7 @@ package e2e
1717import (
1818 "context"
1919 "fmt"
20+ "os"
2021 "reflect"
2122 "strings"
2223 "time"
6667 // ReportAfterEach dumps detailed state for each tracked resource then clears
6768 // the list.
6869 resourcesUnderTest []client.Object
70+
71+ // specDiagnostics stores per-spec diagnostic output keyed by spec text.
72+ // ReportAfterEach populates it on failure; ReportAfterSuite reads it to
73+ // append diagnostics to the JUnit failure message.
74+ specDiagnostics = map [string ]string {}
6975)
7076
7177func init () {
@@ -113,16 +119,16 @@ func trackResource(obj client.Object) {
113119 resourcesUnderTest = append (resourcesUnderTest , obj )
114120}
115121
116- // dumpTrackedResources writes detailed diagnostics for each tracked resource
117- // to GinkgoWriter . For each resource it fetches current state, marshals it as
122+ // collectTrackedResourceDiagnostics builds a diagnostics string for each
123+ // tracked resource . For each resource it fetches current state, marshals it as
118124// YAML, and lists events specific to that object. It also dumps all
119125// AWSMachineTemplates (on AWS) and all events in both namespaces.
120126// Best-effort: panics are recovered and individual errors are logged without
121127// aborting the dump.
122- func dumpTrackedResources () {
128+ func collectTrackedResourceDiagnostics () string {
123129 defer func () {
124130 if r := recover (); r != nil {
125- GinkgoWriter . Printf ( "WARNING: dumpTrackedResources panicked: %v\n " , r )
131+ fmt . Fprintf ( os . Stderr , "WARNING: collectTrackedResourceDiagnostics panicked: %v\n " , r )
126132 }
127133 }()
128134
@@ -141,7 +147,7 @@ func dumpTrackedResources() {
141147
142148 buf .WriteString ("\n === End Test Failure Diagnostics ===\n " )
143149
144- GinkgoWriter . Print ( buf .String () )
150+ return buf .String ()
145151}
146152
147153func dumpSingleResource (buf * strings.Builder , obj client.Object ) {
0 commit comments