(t *testing.T)
| 185 | } |
| 186 | |
| 187 | func TestSaveResponse_CreatesDir(t *testing.T) { |
| 188 | dir := t.TempDir() |
| 189 | origWd, _ := os.Getwd() |
| 190 | os.Chdir(dir) |
| 191 | defer os.Chdir(origWd) |
| 192 | |
| 193 | resp := newApiResp([]byte("data"), map[string]string{"Content-Type": "application/octet-stream"}) |
| 194 | |
| 195 | meta, err := SaveResponse(&localfileio.LocalFileIO{}, resp, filepath.Join("sub", "deep", "out.bin")) |
| 196 | if err != nil { |
| 197 | t.Fatalf("SaveResponse with nested dir failed: %v", err) |
| 198 | } |
| 199 | savedPath, _ := meta["saved_path"].(string) |
| 200 | if _, err := os.Stat(savedPath); err != nil { |
| 201 | t.Errorf("expected file to exist at %s", savedPath) |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | func TestHandleResponse_JSON(t *testing.T) { |
| 206 | body := []byte(`{"code":0,"msg":"ok","data":{"id":"1"}}`) |
nothing calls this directly
no test coverage detected