(t *testing.T)
| 565 | } |
| 566 | |
| 567 | func Test_writeToOutput(t *testing.T) { |
| 568 | tests := []struct { |
| 569 | name string |
| 570 | file *repoFile |
| 571 | output string |
| 572 | clobber bool |
| 573 | lstat func(path string) (*lstatResult, error) |
| 574 | wantDest string |
| 575 | wantWrite string |
| 576 | wantDir string |
| 577 | wantErr string |
| 578 | }{ |
| 579 | { |
| 580 | name: "writes to a new file path", |
| 581 | file: &repoFile{Name: "README.md", Content: []byte("hi")}, |
| 582 | output: "out/README.md", |
| 583 | lstat: func(string) (*lstatResult, error) { return nil, fs.ErrNotExist }, |
| 584 | wantDest: "out/README.md", |
| 585 | wantWrite: "hi", |
| 586 | wantDir: "out", |
| 587 | }, |
| 588 | { |
| 589 | name: "directory target uses remote basename", |
| 590 | file: &repoFile{Name: "README.md", Content: []byte("hi")}, |
| 591 | output: "out/", |
| 592 | lstat: func(path string) (*lstatResult, error) { |
| 593 | if path == "out/" { |
| 594 | return &lstatResult{isDir: true}, nil |
| 595 | } |
| 596 | return nil, fs.ErrNotExist |
| 597 | }, |
| 598 | wantDest: filepath.Join("out", "README.md"), |
| 599 | wantWrite: "hi", |
| 600 | wantDir: "out", |
| 601 | }, |
| 602 | { |
| 603 | name: "existing file without clobber errors", |
| 604 | file: &repoFile{Name: "README.md", Content: []byte("hi")}, |
| 605 | output: "README.md", |
| 606 | lstat: func(string) (*lstatResult, error) { return &lstatResult{}, nil }, |
| 607 | wantErr: `output path already exists: "README.md" (use --clobber to overwrite)`, |
| 608 | }, |
| 609 | { |
| 610 | name: "existing file with clobber overwrites", |
| 611 | file: &repoFile{Name: "README.md", Content: []byte("hi")}, |
| 612 | output: "README.md", |
| 613 | clobber: true, |
| 614 | lstat: func(string) (*lstatResult, error) { return &lstatResult{}, nil }, |
| 615 | wantDest: "README.md", |
| 616 | wantWrite: "hi", |
| 617 | }, |
| 618 | { |
| 619 | name: "symlink target is refused", |
| 620 | file: &repoFile{Name: "README.md", Content: []byte("hi")}, |
| 621 | output: "link.md", |
| 622 | lstat: func(string) (*lstatResult, error) { return &lstatResult{isSymlink: true}, nil }, |
| 623 | wantErr: "output path is a symlink", |
| 624 | }, |
nothing calls this directly
no test coverage detected