(t *testing.T)
| 481 | } |
| 482 | |
| 483 | func TestPutRecursive_WalksDirectoryStructure(t *testing.T) { |
| 484 | dir := t.TempDir() |
| 485 | if err := os.MkdirAll(filepath.Join(dir, "sub", "deep"), 0755); err != nil { |
| 486 | t.Fatal(err) |
| 487 | } |
| 488 | if err := os.WriteFile(filepath.Join(dir, "root.txt"), []byte("root"), 0644); err != nil { |
| 489 | t.Fatal(err) |
| 490 | } |
| 491 | if err := os.WriteFile(filepath.Join(dir, "sub", "mid.txt"), []byte("mid"), 0644); err != nil { |
| 492 | t.Fatal(err) |
| 493 | } |
| 494 | if err := os.WriteFile(filepath.Join(dir, "sub", "deep", "leaf.txt"), []byte("leaf"), 0644); err != nil { |
| 495 | t.Fatal(err) |
| 496 | } |
| 497 | |
| 498 | var uploaded []string |
| 499 | origConfig := config |
| 500 | defer func() { config = origConfig }() |
| 501 | |
| 502 | config = testConfig() |
| 503 | testClient := &mockFilesClient{ |
| 504 | uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) { |
| 505 | uploaded = append(uploaded, arg.Path) |
| 506 | return &files.FileMetadata{}, nil |
| 507 | }, |
| 508 | } |
| 509 | origNew := filesNewFunc |
| 510 | filesNewFunc = func(_ dropbox.Config) filesClient { return testClient } |
| 511 | defer func() { filesNewFunc = origNew }() |
| 512 | |
| 513 | opts := putOptions{chunkSize: 1 << 24, workers: 4} |
| 514 | err := putRecursive(dir, "/backup", opts) |
| 515 | if err != nil { |
| 516 | t.Fatalf("putRecursive error: %v", err) |
| 517 | } |
| 518 | |
| 519 | expected := map[string]bool{ |
| 520 | "/backup/root.txt": true, |
| 521 | "/backup/sub/mid.txt": true, |
| 522 | "/backup/sub/deep/leaf.txt": true, |
| 523 | } |
| 524 | if len(uploaded) != len(expected) { |
| 525 | t.Fatalf("uploaded %d files, want %d: %v", len(uploaded), len(expected), uploaded) |
| 526 | } |
| 527 | for _, path := range uploaded { |
| 528 | if !expected[path] { |
| 529 | t.Errorf("unexpected upload path: %s", path) |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | func TestPutRecursive_CreatesEmptyDirectories(t *testing.T) { |
| 535 | dir := t.TempDir() |
nothing calls this directly
no test coverage detected