Merge pull request #96906 from Rajalakshmi-Girish/issue-96853

Fixes the unit tests to be more tolerant with error messages
This commit is contained in:
Kubernetes Prow Robot 2021-01-05 17:09:51 -08:00 committed by GitHub
commit 10c1c3acf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 6 deletions

View File

@ -227,8 +227,8 @@ func TestCheckpointStateRestore(t *testing.T) {
restoredState, err := NewCheckpointState(testingDir, testingCheckpoint, tc.policyName, tc.initialContainers) restoredState, err := NewCheckpointState(testingDir, testingCheckpoint, tc.policyName, tc.initialContainers)
if err != nil { if err != nil {
if strings.TrimSpace(tc.expectedError) != "" { if strings.TrimSpace(tc.expectedError) != "" {
tc.expectedError = "could not restore state from checkpoint: " + tc.expectedError if strings.Contains(err.Error(), "could not restore state from checkpoint") &&
if strings.HasPrefix(err.Error(), tc.expectedError) { strings.Contains(err.Error(), tc.expectedError) {
t.Logf("got expected error: %v", err) t.Logf("got expected error: %v", err)
return return
} }

View File

@ -123,7 +123,7 @@ func TestStrategicMergePatchInvalid(t *testing.T) {
if !apierrors.IsBadRequest(err) { if !apierrors.IsBadRequest(err) {
t.Errorf("expected HTTP status: BadRequest, got: %#v", apierrors.ReasonForError(err)) t.Errorf("expected HTTP status: BadRequest, got: %#v", apierrors.ReasonForError(err))
} }
if err.Error() != expectedError { if !strings.Contains(err.Error(), expectedError) {
t.Errorf("expected %#v, got %#v", expectedError, err.Error()) t.Errorf("expected %#v, got %#v", expectedError, err.Error())
} }
} }
@ -171,7 +171,7 @@ func TestJSONPatch(t *testing.T) {
t.Errorf("%s: expect no error when applying json patch, but got %v", test.name, err) t.Errorf("%s: expect no error when applying json patch, but got %v", test.name, err)
continue continue
} }
if err.Error() != test.expectedError { if !strings.Contains(err.Error(), test.expectedError) {
t.Errorf("%s: expected error %v, but got %v", test.name, test.expectedError, err) t.Errorf("%s: expected error %v, but got %v", test.name, test.expectedError, err)
} }
if test.expectedErrorType != apierrors.ReasonForError(err) { if test.expectedErrorType != apierrors.ReasonForError(err) {

View File

@ -18,6 +18,7 @@ package remotecommand
import ( import (
"fmt" "fmt"
"strings"
"testing" "testing"
) )
@ -36,7 +37,7 @@ func TestV4ErrorDecoder(t *testing.T) {
}, },
{ {
message: "{", message: "{",
err: "error stream protocol error: unexpected end of JSON input in \"{\"", err: "unexpected end of JSON input in \"{\"",
}, },
{ {
message: `{"status": "Success" }`, message: `{"status": "Success" }`,
@ -64,7 +65,7 @@ func TestV4ErrorDecoder(t *testing.T) {
if want == "" { if want == "" {
want = "<nil>" want = "<nil>"
} }
if got := fmt.Sprintf("%v", err); got != want { if got := fmt.Sprintf("%v", err); !strings.Contains(got, want) {
t.Errorf("wrong error for message %q: want=%q, got=%q", test.message, want, got) t.Errorf("wrong error for message %q: want=%q, got=%q", test.message, want, got)
} }
} }