(t *testing.T)
| 1422 | } |
| 1423 | |
| 1424 | func 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 | |
| 1479 | func TestUploadChunked_RetriesSessionStart(t *testing.T) { |
| 1480 | stubRetrySleep(t) |
nothing calls this directly
no test coverage detected