DRA scheduler: fix potential panic during unit test verification

If there was an unexpected status, the code extracting the expected error
message crashed with a panic. Happened once so far, for unknown reasons
because the unexpected status then didn't get logged.
This commit is contained in:
Patrick Ohly 2025-03-18 12:18:25 +01:00
parent bce5886c97
commit d95d6ba526

View File

@ -1047,7 +1047,9 @@ type testContext struct {
func (tc *testContext) verify(t *testing.T, expected result, initialObjects []metav1.Object, result interface{}, status *framework.Status) { func (tc *testContext) verify(t *testing.T, expected result, initialObjects []metav1.Object, result interface{}, status *framework.Status) {
t.Helper() t.Helper()
if actualErr := status.AsError(); actualErr != nil { if expected.status == nil {
assert.Nil(t, status)
} else if actualErr := status.AsError(); actualErr != nil {
// Compare only the error strings. // Compare only the error strings.
assert.ErrorContains(t, actualErr, expected.status.AsError().Error()) assert.ErrorContains(t, actualErr, expected.status.AsError().Error())
} else { } else {