(t *testing.T)
| 207 | } |
| 208 | |
| 209 | func TestGetDownloadRetriesBodyReadError(t *testing.T) { |
| 210 | delays := stubRetrySleep(t) |
| 211 | tmpDir := t.TempDir() |
| 212 | dst := filepath.Join(tmpDir, "downloaded.txt") |
| 213 | content := "complete file content" |
| 214 | |
| 215 | calls := 0 |
| 216 | mock := &mockFilesClient{ |
| 217 | downloadFn: func(arg *files.DownloadArg) (*files.FileMetadata, io.ReadCloser, error) { |
| 218 | calls++ |
| 219 | meta := &files.FileMetadata{ |
| 220 | Metadata: files.Metadata{PathDisplay: "/test.txt"}, |
| 221 | Size: uint64(len(content)), |
| 222 | } |
| 223 | if calls == 1 { |
| 224 | return meta, &failingReadCloser{data: []byte("partial")}, nil |
| 225 | } |
| 226 | return meta, io.NopCloser(strings.NewReader(content)), nil |
| 227 | }, |
| 228 | } |
| 229 | |
| 230 | err := downloadFile(mock, "/test.txt", dst) |
| 231 | if err != nil { |
| 232 | t.Errorf("expected nil error, got %v", err) |
| 233 | } |
| 234 | if calls != 2 { |
| 235 | t.Errorf("expected 2 calls, got %d", calls) |
| 236 | } |
| 237 | if len(*delays) != 1 { |
| 238 | t.Fatalf("expected 1 sleep, got %d", len(*delays)) |
| 239 | } |
| 240 | |
| 241 | got, err := os.ReadFile(dst) |
| 242 | if err != nil { |
| 243 | t.Fatalf("failed to read downloaded file: %v", err) |
| 244 | } |
| 245 | if string(got) != content { |
| 246 | t.Errorf("got %q, want %q", string(got), content) |
| 247 | } |
| 248 | |
| 249 | entries, err := os.ReadDir(tmpDir) |
| 250 | if err != nil { |
| 251 | t.Fatalf("failed to read temp dir: %v", err) |
| 252 | } |
| 253 | if len(entries) != 1 || entries[0].Name() != filepath.Base(dst) { |
| 254 | t.Fatalf("expected only final destination file, got %v", entries) |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | func TestGetDownloadPreservesDestinationSymlink(t *testing.T) { |
| 259 | tmpDir := t.TempDir() |
nothing calls this directly
no test coverage detected