Skip to content

Commit

Permalink
Merge pull request #96906 from Rajalakshmi-Girish/issue-96853
Browse files Browse the repository at this point in the history
Fixes the unit tests to be more tolerant with error messages
  • Loading branch information
k8s-ci-robot committed Jan 6, 2021
2 parents 86f8c3e + 98948ad commit 10c1c3a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/kubelet/cm/cpumanager/state/state_checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions staging/src/k8s.io/client-go/tools/remotecommand/v4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package remotecommand

import (
"fmt"
"strings"
"testing"
)

Expand All @@ -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" }`,
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 10c1c3a

Please sign in to comment.