(t *testing.T)
| 150 | } |
| 151 | |
| 152 | func TestDecodeErrorResponse(t *testing.T) { |
| 153 | testCases := []struct { |
| 154 | response *http.Response |
| 155 | wantMessage string |
| 156 | }{ |
| 157 | { |
| 158 | response: errorResponse418("text/html", "Time for tea"), |
| 159 | wantMessage: `expected response with Content-Type "application/json" but got status "418 I'm a teapot" with Content-Type "text/html"`, |
| 160 | }, |
| 161 | { |
| 162 | response: errorResponse418("application/json", `{"error": {"type": "json", "valid": no}}`), |
| 163 | wantMessage: "failed to parse API error response: invalid character 'o' in literal null (expecting 'u')", |
| 164 | }, |
| 165 | { |
| 166 | response: errorResponse418("application/json; charset=utf-8", `{"error": {"type": "track_ambiguous", "message": "message", "possible_track_ids": ["a", "b"]}}`), |
| 167 | wantMessage: "message: a, b", |
| 168 | }, |
| 169 | { |
| 170 | response: errorResponse418("application/json", `{"error": {"type": "track_ambiguous", "message": "message", "possible_track_ids": ["a", "b"]}}`), |
| 171 | wantMessage: "message: a, b", |
| 172 | }, |
| 173 | { |
| 174 | response: errorResponse418("application/json", `{"error": {"message": "message"}}`), |
| 175 | wantMessage: "message", |
| 176 | }, |
| 177 | { |
| 178 | response: errorResponse418("application/problem+json", `{"error": {"message": "new json format"}}`), |
| 179 | wantMessage: "new json format", |
| 180 | }, |
| 181 | { |
| 182 | response: errorResponse418("application/json", `{"error": {}}`), |
| 183 | wantMessage: "unexpected API response: 418", |
| 184 | }, |
| 185 | { |
| 186 | response: errorResponse429("30"), |
| 187 | wantMessage: "request failed with status 429 Too Many Requests; please try again after 30 seconds", |
| 188 | }, |
| 189 | { |
| 190 | response: errorResponse429("Wed, 21 Oct 2015 07:28:00 GMT"), |
| 191 | wantMessage: "request failed with status 429 Too Many Requests; please try again after Wed, 21 Oct 2015 07:28:00 GMT", |
| 192 | }, |
| 193 | } |
| 194 | tc := testCases[0] |
| 195 | got := decodedAPIError(tc.response) |
| 196 | assert.Equal(t, tc.wantMessage, got.Error()) |
| 197 | for _, tc = range testCases { |
| 198 | got := decodedAPIError(tc.response) |
| 199 | assert.Equal(t, tc.wantMessage, got.Error()) |
| 200 | } |
| 201 | } |
nothing calls this directly
no test coverage detected