MCPcopy
hub / github.com/grpc/grpc-go / TestStatusInvalidUTF8Details

Method TestStatusInvalidUTF8Details

test/end2end_test.go:5828–5863  ·  view source on GitHub ↗

Service handler returns status with details and invalid utf8 message. Proto will fail to marshal the status because of the invalid utf8 message. Details will be dropped when sending.

(t *testing.T)

Source from the content-addressed store, hash-verified

5826// will fail to marshal the status because of the invalid utf8 message. Details
5827// will be dropped when sending.
5828func (s) TestStatusInvalidUTF8Details(t *testing.T) {
5829 grpctest.ExpectError("Failed to marshal rpc status")
5830
5831 var (
5832 origMsg = string([]byte{0xff, 0xfe, 0xfd})
5833 wantMsg = "���"
5834 )
5835
5836 ss := &stubserver.StubServer{
5837 EmptyCallF: func(context.Context, *testpb.Empty) (*testpb.Empty, error) {
5838 st := status.New(codes.Internal, origMsg)
5839 st, err := st.WithDetails(&testpb.Empty{})
5840 if err != nil {
5841 return nil, err
5842 }
5843 return nil, st.Err()
5844 },
5845 }
5846 if err := ss.Start(nil); err != nil {
5847 t.Fatalf("Error starting endpoint server: %v", err)
5848 }
5849 defer ss.Stop()
5850
5851 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
5852 defer cancel()
5853
5854 _, err := ss.Client.EmptyCall(ctx, &testpb.Empty{})
5855 st := status.Convert(err)
5856 if st.Message() != wantMsg {
5857 t.Fatalf("ss.Client.EmptyCall(_, _) = _, %v (msg %q); want _, err with msg %q", err, st.Message(), wantMsg)
5858 }
5859 if len(st.Details()) != 0 {
5860 // Details should be dropped on the server side.
5861 t.Fatalf("RPC status contain details: %v, want no details", st.Details())
5862 }
5863}
5864
5865func (s) TestRPCTimeout(t *testing.T) {
5866 for _, e := range listTestEnv() {

Callers

nothing calls this directly

Calls 9

StartMethod · 0.95
StopMethod · 0.95
ExpectErrorFunction · 0.92
WithDetailsMethod · 0.80
ErrMethod · 0.80
MessageMethod · 0.80
DetailsMethod · 0.80
FatalfMethod · 0.65
EmptyCallMethod · 0.65

Tested by

no test coverage detected