MCPcopy
hub / github.com/connectrpc/connect-go / TestJSONCodec

Function TestJSONCodec

codec_test.go:128–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

126}
127
128func TestJSONCodec(t *testing.T) {
129 t.Parallel()
130
131 codec := &protoJSONCodec{name: codecNameJSON}
132
133 t.Run("success", func(t *testing.T) {
134 t.Parallel()
135 err := codec.Unmarshal([]byte("{}"), &emptypb.Empty{})
136 assert.Nil(t, err)
137 })
138
139 t.Run("unknown fields", func(t *testing.T) {
140 t.Parallel()
141 err := codec.Unmarshal([]byte(`{"foo": "bar"}`), &emptypb.Empty{})
142 assert.Nil(t, err)
143 })
144
145 t.Run("empty string", func(t *testing.T) {
146 t.Parallel()
147 err := codec.Unmarshal([]byte{}, &emptypb.Empty{})
148 assert.NotNil(t, err)
149 assert.True(
150 t,
151 strings.Contains(err.Error(), "valid JSON"),
152 assert.Sprintf(`error message should explain that "" is not a valid JSON object`),
153 )
154 })
155}

Callers

nothing calls this directly

Calls 7

UnmarshalMethod · 0.95
NilFunction · 0.92
NotNilFunction · 0.92
TrueFunction · 0.92
SprintfFunction · 0.92
ErrorMethod · 0.80
ContainsMethod · 0.65

Tested by

no test coverage detected