MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestGetDownloadWithRetry

Function TestGetDownloadWithRetry

cmd/get_test.go:171–207  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

169}
170
171func TestGetDownloadWithRetry(t *testing.T) {
172 stubRetrySleep(t)
173 tmpDir := t.TempDir()
174 dst := filepath.Join(tmpDir, "downloaded.txt")
175 content := "file content here"
176
177 calls := 0
178 mock := &mockFilesClient{
179 downloadFn: func(arg *files.DownloadArg) (*files.FileMetadata, io.ReadCloser, error) {
180 calls++
181 if calls < 3 {
182 return nil, nil, dbxauth.ServerError{APIError: dropbox.APIError{ErrorSummary: "500"}}
183 }
184 meta := &files.FileMetadata{
185 Metadata: files.Metadata{PathDisplay: "/test.txt"},
186 Size: uint64(len(content)),
187 }
188 return meta, io.NopCloser(strings.NewReader(content)), nil
189 },
190 }
191
192 err := downloadFile(mock, "/test.txt", dst)
193 if err != nil {
194 t.Errorf("expected nil error, got %v", err)
195 }
196 if calls != 3 {
197 t.Errorf("expected 3 calls, got %d", calls)
198 }
199
200 got, err := os.ReadFile(dst)
201 if err != nil {
202 t.Fatalf("failed to read downloaded file: %v", err)
203 }
204 if string(got) != content {
205 t.Errorf("got %q, want %q", string(got), content)
206 }
207}
208
209func TestGetDownloadRetriesBodyReadError(t *testing.T) {
210 delays := stubRetrySleep(t)

Callers

nothing calls this directly

Calls 2

stubRetrySleepFunction · 0.85
downloadFileFunction · 0.85

Tested by

no test coverage detected