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

Function TestPutRecursiveIfExistsSkipContinuesPastExistingFiles

cmd/put_test.go:1424–1477  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1422}
1423
1424func TestPutRecursiveIfExistsSkipContinuesPastExistingFiles(t *testing.T) {
1425 dir := t.TempDir()
1426 if err := os.WriteFile(filepath.Join(dir, "existing.txt"), []byte("existing"), 0644); err != nil {
1427 t.Fatal(err)
1428 }
1429 if err := os.WriteFile(filepath.Join(dir, "new.txt"), []byte("new"), 0644); err != nil {
1430 t.Fatal(err)
1431 }
1432
1433 var uploaded []string
1434 mock := &mockFilesClient{
1435 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
1436 if arg.Path == "/backup/existing.txt" {
1437 return &files.FileMetadata{Metadata: files.Metadata{PathDisplay: arg.Path}}, nil
1438 }
1439 return nil, getMetadataNotFoundError()
1440 },
1441 uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) {
1442 uploaded = append(uploaded, arg.Path)
1443 return &files.FileMetadata{}, nil
1444 },
1445 createFolderV2Fn: func(arg *files.CreateFolderArg) (*files.CreateFolderResult, error) {
1446 return &files.CreateFolderResult{}, nil
1447 },
1448 }
1449 stubFilesClient(t, mock)
1450
1451 var stderr bytes.Buffer
1452 cmd := testPutCmd()
1453 cmd.SetErr(&stderr)
1454
1455 err := putRecursive(dir, "/backup", putOptions{
1456 chunkSize: 1 << 24,
1457 workers: 4,
1458 ifExists: putIfExistsSkip,
1459 output: commandOutput(cmd),
1460 })
1461 if err != nil {
1462 t.Fatalf("putRecursive error: %v", err)
1463 }
1464
1465 if len(uploaded) != 1 || uploaded[0] != "/backup/new.txt" {
1466 t.Fatalf("uploaded = %v, want [/backup/new.txt]", uploaded)
1467 }
1468 if strings.Contains(stderr.String(), "Uploading ") {
1469 t.Fatalf("stderr = %q, should not print uploading before skip decision", stderr.String())
1470 }
1471 if !strings.Contains(stderr.String(), "Processing ") {
1472 t.Fatalf("stderr = %q, want processing status", stderr.String())
1473 }
1474 if !strings.Contains(stderr.String(), "Skipping /backup/existing.txt") {
1475 t.Fatalf("stderr = %q, want skip status", stderr.String())
1476 }
1477}
1478
1479func TestUploadChunked_RetriesSessionStart(t *testing.T) {
1480 stubRetrySleep(t)

Callers

nothing calls this directly

Calls 5

getMetadataNotFoundErrorFunction · 0.85
stubFilesClientFunction · 0.85
testPutCmdFunction · 0.85
putRecursiveFunction · 0.85
commandOutputFunction · 0.85

Tested by

no test coverage detected