REST treats 204 and 205 specially and decodes every other 2xx as JSON. Request must do neither, so that bodiless successes and non-JSON successes both work.
(t *testing.T)
| 139 | // REST treats 204 and 205 specially and decodes every other 2xx as JSON. Request must do neither, |
| 140 | // so that bodiless successes and non-JSON successes both work. |
| 141 | func TestRequestDoesNotDecodeSuccessfulResponses(t *testing.T) { |
| 142 | tests := []struct { |
| 143 | name string |
| 144 | statusCode int |
| 145 | body string |
| 146 | }{ |
| 147 | {name: "bodiless 200, as returned by HEAD", statusCode: 200, body: ""}, |
| 148 | {name: "no content", statusCode: 204, body: ""}, |
| 149 | {name: "non-JSON body", statusCode: 200, body: "d3f9c4a"}, |
| 150 | } |
| 151 | |
| 152 | for _, tt := range tests { |
| 153 | t.Run(tt.name, func(t *testing.T) { |
| 154 | reg := &httpmock.Registry{} |
| 155 | defer reg.Verify(t) |
| 156 | client := newTestClient(reg) |
| 157 | |
| 158 | reg.Register(httpmock.MatchAny, httpmock.StatusStringResponse(tt.statusCode, tt.body)) |
| 159 | |
| 160 | resp, err := client.Request("github.com", http.MethodGet, "repos/OWNER/REPO", nil) |
| 161 | require.NoError(t, err) |
| 162 | defer resp.Body.Close() |
| 163 | |
| 164 | assert.Equal(t, tt.statusCode, resp.StatusCode) |
| 165 | }) |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | func TestRequestError(t *testing.T) { |
| 170 | reg := &httpmock.Registry{} |
nothing calls this directly
no test coverage detected