Skip to content

Commit

Permalink
Merge pull request #1720 from SaschaSchwarze0/sascha-fix-npe
Browse files Browse the repository at this point in the history
Fix nil pointer access in AfterEach of failed e2e test cases
  • Loading branch information
openshift-merge-bot[bot] authored Nov 4, 2024
2 parents bc67868 + 8aeb2df commit ee4dca8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 10 additions & 2 deletions test/e2e/v1alpha1/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion test/e2e/v1beta1/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit ee4dca8

Please sign in to comment.