@@ -41,7 +41,8 @@ func (r *testSuiteRunnerImpl) RunOneTest(ctx context.Context, test *testCase) {
4141 // however, we can change the values of the content, so we assign the content lower down to have a cleaner set of
4242 // the many defers in this function.
4343 // remember that defers are last-added, first-executed.
44- testRunResult := & testRunResultHandle {}
44+ // Initialize with a non-nil inner struct so deferred functions can safely read fields
45+ testRunResult := & testRunResultHandle {testRunResult : & testRunResult {testState : TestUnknown }}
4546
4647 // if we need to abort, then abort
4748 defer r .maybeAbortOnFailureFn (testRunResult )
@@ -225,6 +226,10 @@ func recordTestResultInLog(testRunResult *testRunResultHandle, out io.Writer, in
225226 fmt .Fprintln (os .Stderr , "testRunResult is nil" )
226227 return
227228 }
229+ if testRunResult .testRunResult == nil {
230+ fmt .Fprintln (os .Stderr , "testRunResult.testRunResult is nil" )
231+ return
232+ }
228233
229234 // output the status of the test
230235 switch testRunResult .testState {
@@ -267,6 +272,11 @@ func recordTestResultInMonitor(testRunResult *testRunResultHandle, monitorRecord
267272 return
268273 }
269274
275+ if testRunResult .testRunResult == nil {
276+ fmt .Fprintln (os .Stderr , "testRunResult.testRunResult is nil" )
277+ return
278+ }
279+
270280 eventLevel := monitorapi .Warning
271281
272282 msg := monitorapi .NewMessage ().HumanMessage ("e2e test finished" )
@@ -363,15 +373,21 @@ func updateEnvVars(envs []string) []string {
363373 // copied from provider.go
364374 // TODO: add error handling, and maybe turn this into sharable helper?
365375 config := & clusterdiscovery.ClusterConfiguration {}
366- clientConfig , _ := framework .LoadConfig (true )
367- clusterState , _ := clusterdiscovery .DiscoverClusterState (clientConfig )
368- if clusterState != nil {
369- config , _ = clusterdiscovery .LoadConfig (clusterState )
376+ if clientConfig , err := framework .LoadConfig (true ); err == nil {
377+ if clusterState , err := clusterdiscovery .DiscoverClusterState (clientConfig ); err == nil && clusterState != nil {
378+ if loaded , err := clusterdiscovery .LoadConfig (clusterState ); err == nil && loaded != nil {
379+ config = loaded
380+ }
381+ }
370382 }
371383 if len (config .ProviderName ) == 0 {
372384 config .ProviderName = "skeleton"
373385 }
374- provider , _ := json .Marshal (config )
375- result = append (result , fmt .Sprintf ("TEST_PROVIDER=%s" , provider ))
386+ if provider , err := json .Marshal (config ); err == nil {
387+ result = append (result , fmt .Sprintf ("TEST_PROVIDER=%s" , provider ))
388+ } else {
389+ // fallback to a minimal default if marshal fails for any reason
390+ result = append (result , "TEST_PROVIDER=\" {\\ \" ProviderName\\ \" :\\ \" skeleton\\ \" }\" " )
391+ }
376392 return result
377393}
0 commit comments