(t *testing.T)
| 129 | } |
| 130 | |
| 131 | func TestResponseEncoder(t *testing.T) { |
| 132 | cases := []struct { |
| 133 | name string |
| 134 | contentType string |
| 135 | acceptType string |
| 136 | encoderType string |
| 137 | }{ |
| 138 | {"no ct, no at", "", "", "*json.Encoder"}, |
| 139 | {"no ct, at json", "", "application/json", "*json.Encoder"}, |
| 140 | {"no ct, at xml", "", "application/xml", "*xml.Encoder"}, |
| 141 | {"no ct, at gob", "", "application/gob", "*gob.Encoder"}, |
| 142 | {"no ct, at html", "", "text/html", "*http.textEncoder"}, |
| 143 | {"no ct, at plain", "", "text/plain", "*http.textEncoder"}, |
| 144 | {"ct json", "application/json", "application/gob", "*json.Encoder"}, |
| 145 | {"ct +json", "+json", "application/gob", "*json.Encoder"}, |
| 146 | {"ct xml", "application/xml", "application/gob", "*xml.Encoder"}, |
| 147 | {"ct +xml", "+xml", "application/gob", "*xml.Encoder"}, |
| 148 | {"ct gob", "application/gob", "application/xml", "*gob.Encoder"}, |
| 149 | {"ct +gob", "+gob", "application/xml", "*gob.Encoder"}, |
| 150 | {"ct html", "text/html", "application/gob", "*http.textEncoder"}, |
| 151 | {"ct +html", "+html", "application/gob", "*http.textEncoder"}, |
| 152 | {"ct plain", "text/plain", "application/gob", "*http.textEncoder"}, |
| 153 | {"ct +txt", "+txt", "application/gob", "*http.textEncoder"}, |
| 154 | {"no ct, at json with params", "", "application/json; charset=utf-8", "*json.Encoder"}, |
| 155 | {"no ct, at xml with params", "", "application/xml; charset=utf-8", "*xml.Encoder"}, |
| 156 | {"no ct, at gob with params", "", "application/gob; charset=utf-8", "*gob.Encoder"}, |
| 157 | {"no ct, at html with params", "", "text/html; charset=utf-8", "*http.textEncoder"}, |
| 158 | {"no ct, at plain with params", "", "text/plain; charset=utf-8", "*http.textEncoder"}, |
| 159 | {"ct json with params", "application/json; charset=utf-8", "application/gob", "*json.Encoder"}, |
| 160 | {"ct +json with params", "+json; charset=utf-8", "application/gob", "*json.Encoder"}, |
| 161 | {"ct xml with params", "application/xml; charset=utf-8", "application/gob", "*xml.Encoder"}, |
| 162 | {"ct +xml with params", "+xml; charset=utf-8", "application/gob", "*xml.Encoder"}, |
| 163 | {"ct gob with params", "application/gob; charset=utf-8", "application/xml", "*gob.Encoder"}, |
| 164 | {"ct +gob with params", "+gob; charset=utf-8", "application/xml", "*gob.Encoder"}, |
| 165 | {"ct html with params", "text/html; charset=utf-8", "application/gob", "*http.textEncoder"}, |
| 166 | {"ct +html with params", "+html; charset=utf-8", "application/gob", "*http.textEncoder"}, |
| 167 | {"ct plain with params", "text/plain; charset=utf-8", "application/gob", "*http.textEncoder"}, |
| 168 | {"ct +txt with params", "+txt; charset=utf-8", "application/gob", "*http.textEncoder"}, |
| 169 | } |
| 170 | |
| 171 | for _, c := range cases { |
| 172 | t.Run(c.name, func(t *testing.T) { |
| 173 | ctx := context.Background() |
| 174 | ctx = context.WithValue(ctx, AcceptTypeKey, c.acceptType) |
| 175 | ctx = context.WithValue(ctx, ContentTypeKey, c.contentType) |
| 176 | w := httptest.NewRecorder() |
| 177 | |
| 178 | encoder := ResponseEncoder(ctx, w) |
| 179 | |
| 180 | assert.Equal(t, c.encoderType, fmt.Sprintf("%T", encoder)) |
| 181 | }) |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | func TestResponseEncoder_ContentTypeHeaderPreservesCharset(t *testing.T) { |
| 186 | ctx := context.Background() |
nothing calls this directly
no test coverage detected