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

Function TestRequestDecoder

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

Source from the content-addressed store, hash-verified

78}
79
80func TestRequestDecoder(t *testing.T) {
81 const (
82 ct = "Content-Type"
83 ctJSON = "application/json"
84 ctXML = "application/xml"
85 ctGob = "application/gob"
86 unsupportedT = "*http.unsupportedDecoder"
87 jsonT = "*json.Decoder"
88 xmlT = "*xml.Decoder"
89 gobT = "*gob.Decoder"
90 )
91 cases := []struct {
92 name string
93 requestCT string
94 wantCT string
95 }{
96 {"no ct", "", jsonT},
97 {"unsupported ct", "application/foo", unsupportedT},
98 {"json ct", ctJSON, jsonT},
99 {"xml ct", ctXML, xmlT},
100 {"gob ct", ctGob, gobT},
101 }
102 for _, c := range cases {
103 t.Run(c.name, func(t *testing.T) {
104 r := &http.Request{Header: http.Header{}}
105 if c.requestCT != "" {
106 r.Header.Set(ct, c.requestCT)
107 }
108
109 decoder := RequestDecoder(r)
110
111 assert.Equal(t, c.wantCT, fmt.Sprintf("%T", decoder))
112 })
113 }
114}
115
116func TestUnsupportedDecoder(t *testing.T) {
117 // Write the response produced when writing the error returned the

Callers

nothing calls this directly

Calls 3

SetMethod · 0.80
RequestDecoderFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected