(t *testing.T)
| 261 | } |
| 262 | |
| 263 | func TestHandleResponse_JSONWithError(t *testing.T) { |
| 264 | body := []byte(`{"code":99991400,"msg":"invalid token"}`) |
| 265 | resp := newApiResp(body, map[string]string{"Content-Type": "application/json"}) |
| 266 | |
| 267 | var out bytes.Buffer |
| 268 | var errOut bytes.Buffer |
| 269 | err := HandleResponse(resp, ResponseOptions{ |
| 270 | Out: &out, |
| 271 | ErrOut: &errOut, |
| 272 | FileIO: &localfileio.LocalFileIO{}, |
| 273 | }) |
| 274 | if err == nil { |
| 275 | t.Error("expected error for non-zero code") |
| 276 | } |
| 277 | if _, ok := errs.ProblemOf(err); !ok { |
| 278 | t.Fatalf("expected typed error, got %T: %v", err, err) |
| 279 | } |
| 280 | if strings.Contains(out.String(), `"ok": true`) || strings.Contains(out.String(), `"ok":true`) { |
| 281 | t.Fatalf("unexpected success envelope on error path: %s", out.String()) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | func TestHandleResponse_BinaryAutoSave(t *testing.T) { |
| 286 | dir := t.TempDir() |
nothing calls this directly
no test coverage detected