MCPcopy Create free account
hub / github.com/cli/cli / Test_writeToOutput

Function Test_writeToOutput

pkg/cmd/repo/read-file/read_file_test.go:612–1031  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

610}
611
612func 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" {

Callers

nothing calls this directly

Calls 12

writeToOutputFunction · 0.85
JoinMethod · 0.80
WriteFileMethod · 0.80
ModeMethod · 0.80
EqualMethod · 0.80
setupMethod · 0.80
EmptyMethod · 0.80
ErrorfMethod · 0.65
HelperMethod · 0.65
RunMethod · 0.65
verifyMethod · 0.65
CleanMethod · 0.45

Tested by

no test coverage detected