mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
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:
commit
10c1c3acf6
@ -227,8 +227,8 @@ func TestCheckpointStateRestore(t *testing.T) {
|
||||
restoredState, err := NewCheckpointState(testingDir, testingCheckpoint, tc.policyName, tc.initialContainers)
|
||||
if err != nil {
|
||||
if strings.TrimSpace(tc.expectedError) != "" {
|
||||
tc.expectedError = "could not restore state from checkpoint: " + tc.expectedError
|
||||
if strings.HasPrefix(err.Error(), tc.expectedError) {
|
||||
if strings.Contains(err.Error(), "could not restore state from checkpoint") &&
|
||||
strings.Contains(err.Error(), tc.expectedError) {
|
||||
t.Logf("got expected error: %v", err)
|
||||
return
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ func TestStrategicMergePatchInvalid(t *testing.T) {
|
||||
if !apierrors.IsBadRequest(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())
|
||||
}
|
||||
}
|
||||
@ -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)
|
||||
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)
|
||||
}
|
||||
if test.expectedErrorType != apierrors.ReasonForError(err) {
|
||||
|
@ -18,6 +18,7 @@ package remotecommand
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -36,7 +37,7 @@ func TestV4ErrorDecoder(t *testing.T) {
|
||||
},
|
||||
{
|
||||
message: "{",
|
||||
err: "error stream protocol error: unexpected end of JSON input in \"{\"",
|
||||
err: "unexpected end of JSON input in \"{\"",
|
||||
},
|
||||
{
|
||||
message: `{"status": "Success" }`,
|
||||
@ -64,7 +65,7 @@ func TestV4ErrorDecoder(t *testing.T) {
|
||||
if want == "" {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user