From 8aeb2dfe35e707dc1de2fb290a231877aff6f617 Mon Sep 17 00:00:00 2001 From: Sascha Schwarze Date: Mon, 4 Nov 2024 11:45:15 +0100 Subject: [PATCH] Fix nil pointer access in AfterEach of failed e2e test cases Signed-off-by: Sascha Schwarze --- test/e2e/v1alpha1/common_test.go | 12 ++++++++++-- test/e2e/v1beta1/common_test.go | 10 +++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/test/e2e/v1alpha1/common_test.go b/test/e2e/v1alpha1/common_test.go index 43111cecee..a6835e970e 100644 --- a/test/e2e/v1alpha1/common_test.go +++ b/test/e2e/v1alpha1/common_test.go @@ -165,7 +165,15 @@ func printTestFailureDebugInfo(testBuild *utils.TestBuild, namespace string, bui } if build != nil { - Logf("The status of Build %s: registered=%s, reason=%s", build.Name, *build.Status.Registered, *build.Status.Reason) + registered := "nil" + if build.Status.Registered != nil { + registered = string(*build.Status.Registered) + } + reason := "nil" + if build.Status.Reason != nil { + reason = string(*build.Status.Reason) + } + Logf("The status of Build %s: registered=%s, reason=%s", build.Name, registered, reason) if buildJSON, err := json.Marshal(build); err == nil { Logf("The full Build: %s", string(buildJSON)) } @@ -255,7 +263,7 @@ func printTestFailureDebugInfo(testBuild *utils.TestBuild, namespace string, bui func GetBuildObject(ctx context.Context, client client.Client, buildRun *buildv1alpha1.BuildRun, build *buildv1alpha1.Build) error { // Option #1: BuildRef is specified // An actual Build resource is specified by name and needs to be looked up in the cluster. - if buildRun.Spec.BuildRef.Name != "" { + if buildRun.Spec.BuildRef != nil && buildRun.Spec.BuildRef.Name != "" { err := client.Get(ctx, types.NamespacedName{Name: buildRun.Spec.BuildName(), Namespace: buildRun.Namespace}, build) if apierrors.IsNotFound(err) { // stop reconciling and mark the BuildRun as Failed diff --git a/test/e2e/v1beta1/common_test.go b/test/e2e/v1beta1/common_test.go index a629556082..40c71e64be 100644 --- a/test/e2e/v1beta1/common_test.go +++ b/test/e2e/v1beta1/common_test.go @@ -161,7 +161,15 @@ func printTestFailureDebugInfo(testBuild *utils.TestBuild, namespace string, bui } if build != nil { - Logf("The status of Build %s: registered=%s, reason=%s", build.Name, *build.Status.Registered, *build.Status.Reason) + registered := "nil" + if build.Status.Registered != nil { + registered = string(*build.Status.Registered) + } + reason := "nil" + if build.Status.Reason != nil { + reason = string(*build.Status.Reason) + } + Logf("The status of Build %s: registered=%s, reason=%s", build.Name, registered, reason) if buildJSON, err := json.Marshal(build); err == nil { Logf("The full Build: %s", string(buildJSON)) }