mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +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)
|
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
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user