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

Function TestGetRecursive_ReportsDownloadErrors

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

Source from the content-addressed store, hash-verified

452}
453
454func TestGetRecursive_ReportsDownloadErrors(t *testing.T) {
455 tmpDir := t.TempDir()
456 dst := filepath.Join(tmpDir, "output")
457
458 mock := &mockFilesClient{
459 listFolderFn: func(arg *files.ListFolderArg) (*files.ListFolderResult, error) {
460 return &files.ListFolderResult{
461 Entries: []files.IsMetadata{
462 &files.FileMetadata{Metadata: files.Metadata{PathDisplay: "/remote/good.txt"}, Size: 4},
463 &files.FileMetadata{Metadata: files.Metadata{PathDisplay: "/remote/bad.txt"}, Size: 4},
464 },
465 HasMore: false,
466 }, nil
467 },
468 downloadFn: func(arg *files.DownloadArg) (*files.FileMetadata, io.ReadCloser, error) {
469 if strings.Contains(arg.Path, "bad.txt") {
470 return nil, nil, &files.DownloadAPIError{}
471 }
472 meta := &files.FileMetadata{
473 Metadata: files.Metadata{PathDisplay: arg.Path},
474 Size: 4,
475 }
476 return meta, io.NopCloser(strings.NewReader("data")), nil
477 },
478 }
479
480 var err error
481 captureStderr(t, func() {
482 err = getRecursive(mock, "/remote", dst)
483 })
484 if err == nil {
485 t.Fatal("expected error for failed downloads")
486 }
487 if !strings.Contains(err.Error(), "1 error") {
488 t.Errorf("error = %q, want mention of 1 error", err.Error())
489 }
490
491 // Good file should still have been downloaded
492 if _, statErr := os.Stat(filepath.Join(dst, "good.txt")); statErr != nil {
493 t.Errorf("good.txt not downloaded: %v", statErr)
494 }
495}
496
497func TestGetFolderWithoutRecursiveFlag(t *testing.T) {
498 mock := &mockFilesClient{

Callers

nothing calls this directly

Calls 3

captureStderrFunction · 0.85
getRecursiveFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected