MCPcopy Create free account
hub / github.com/goadesign/goa / TestTextEncoder_Encode

Function TestTextEncoder_Encode

http/encoding_test.go:276–303  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

274}
275
276func TestTextEncoder_Encode(t *testing.T) {
277 cases := []struct {
278 name string
279 value any
280 error error
281 }{
282 {"string", testString, nil},
283 {"*string", &testString, nil},
284 {"[]byte", []byte(testString), nil},
285 {"other", 123, fmt.Errorf("can't encode int as content/type")},
286 }
287
288 buffer := bytes.Buffer{}
289 encoder := newTextEncoder(&buffer, "content/type")
290
291 for _, c := range cases {
292 t.Run(c.name, func(t *testing.T) {
293 buffer.Reset()
294 err := encoder.Encode(c.value)
295 if c.error != nil {
296 assert.Error(t, err, c.error)
297 return
298 }
299 require.NoError(t, err)
300 assert.Equal(t, testString, buffer.String())
301 })
302 }
303}
304
305func TestTextPlainDecoder_Decode_String(t *testing.T) {
306 decoder := makeTextDecoder()

Callers

nothing calls this directly

Calls 6

newTextEncoderFunction · 0.85
EncodeMethod · 0.65
StringMethod · 0.65
RunMethod · 0.45
ResetMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected