(t *testing.T)
| 145 | } |
| 146 | |
| 147 | func TestHandleErrorResponse401ValidBody(t *testing.T) { |
| 148 | json := []byte("{\"errors\":[{\"code\":\"UNAUTHORIZED\",\"message\":\"action requires authentication\"}]}") |
| 149 | response := &http.Response{ |
| 150 | Status: "401 Unauthorized", |
| 151 | StatusCode: 401, |
| 152 | Body: io.NopCloser(bytes.NewReader(json)), |
| 153 | } |
| 154 | err := handleErrorResponse(response) |
| 155 | |
| 156 | expectedMsg := "unauthorized: action requires authentication" |
| 157 | if !strings.Contains(err.Error(), expectedMsg) { |
| 158 | t.Errorf("Expected \"%s\", got: \"%s\"", expectedMsg, err.Error()) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | func TestHandleErrorResponse401WithInvalidBody(t *testing.T) { |
| 163 | json := []byte("{invalid json}") |
nothing calls this directly
no test coverage detected
searching dependent graphs…