(t *testing.T)
| 78 | } |
| 79 | |
| 80 | func 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 | |
| 116 | func TestUnsupportedDecoder(t *testing.T) { |
| 117 | // Write the response produced when writing the error returned the |
nothing calls this directly
no test coverage detected