(t *testing.T)
| 610 | } |
| 611 | |
| 612 | func Test_writeToOutput(t *testing.T) { |
| 613 | var clobberTarget string |
| 614 | var danglingTarget string |
| 615 | var ancestorTarget string |
| 616 | var outputDirTarget string |
| 617 | var regularMode os.FileMode |
| 618 | backslashBasename := `nested\README.md` |
| 619 | backslashTraversalBasename := `..\..\README.md` |
| 620 | if runtime.GOOS == "windows" { |
| 621 | backslashBasename = "README.md" |
| 622 | backslashTraversalBasename = "README.md" |
| 623 | } |
| 624 | |
| 625 | tests := []struct { |
| 626 | name string |
| 627 | file *repoFile |
| 628 | output string |
| 629 | clobber bool |
| 630 | lstat func(path string) (*lstatResult, error) |
| 631 | setup func(t *testing.T) |
| 632 | useRealFS bool |
| 633 | verify func(t *testing.T) |
| 634 | wantDest string |
| 635 | wantWrite string |
| 636 | wantDir string |
| 637 | wantLstatPaths []string |
| 638 | wantErr string |
| 639 | }{ |
| 640 | { |
| 641 | name: "writes to a new file path", |
| 642 | file: &repoFile{Name: "README.md", Content: []byte("hi")}, |
| 643 | output: "out/README.md", |
| 644 | lstat: func(string) (*lstatResult, error) { return nil, fs.ErrNotExist }, |
| 645 | wantDest: "out/README.md", |
| 646 | wantWrite: "hi", |
| 647 | wantDir: "out", |
| 648 | }, |
| 649 | { |
| 650 | name: "directory target uses remote basename", |
| 651 | file: &repoFile{Name: "nested/README.md", Content: []byte("hi")}, |
| 652 | output: "out/", |
| 653 | lstat: func(path string) (*lstatResult, error) { |
| 654 | if path == "out" { |
| 655 | return &lstatResult{isDir: true}, nil |
| 656 | } |
| 657 | return nil, fs.ErrNotExist |
| 658 | }, |
| 659 | wantDest: filepath.Join("out", "README.md"), |
| 660 | wantWrite: "hi", |
| 661 | wantDir: "out", |
| 662 | wantLstatPaths: []string{"out", filepath.Join("out", "README.md")}, |
| 663 | }, |
| 664 | { |
| 665 | name: "existing directory without separator uses remote basename", |
| 666 | file: &repoFile{Name: "nested/README.md", Content: []byte("hi")}, |
| 667 | output: "out", |
| 668 | lstat: func(path string) (*lstatResult, error) { |
| 669 | if path == "out" { |
nothing calls this directly
no test coverage detected