test: loosen metadata error check to reduce dependence on exact library errors (#5650)

This commit is contained in:
Doug Fawley 2022-09-12 22:20:29 +00:00 committed by GitHub
parent 552de12024
commit 21f0259e42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -23,6 +23,7 @@ import (
"fmt"
"io"
"reflect"
"strings"
"testing"
"time"
@ -45,12 +46,12 @@ func (s) TestInvalidMetadata(t *testing.T) {
{
md: map[string][]string{string(rune(0x19)): {"testVal"}},
want: status.Error(codes.Internal, "header key \"\\x19\" contains illegal characters not in [0-9a-z-_.]"),
recv: status.Error(codes.Internal, "invalid header field name \"\\x19\""),
recv: status.Error(codes.Internal, "invalid header field"),
},
{
md: map[string][]string{"test": {string(rune(0x19))}},
want: status.Error(codes.Internal, "header key \"test\" contains value with non-printable ASCII characters"),
recv: status.Error(codes.Internal, "invalid header field value \"\\x19\""),
recv: status.Error(codes.Internal, "invalid header field"),
},
{
md: map[string][]string{"test-bin": {string(rune(0x19))}},
@ -113,7 +114,7 @@ func (s) TestInvalidMetadata(t *testing.T) {
if err := stream.Send(&testpb.StreamingOutputCallRequest{}); err != nil {
t.Errorf("call ss.Client stream Send(nil) will success but got err :%v", err)
}
if _, err := stream.Recv(); !reflect.DeepEqual(test.recv, err) {
if _, err := stream.Recv(); status.Code(err) != status.Code(test.recv) || !strings.Contains(err.Error(), test.recv.Error()) {
t.Errorf("stream.Recv() = _, get err :%v, want err :%v", err, test.recv)
}
}