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

Function Test_writeToOutput

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

Source from the content-addressed store, hash-verified

565}
566
567func 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 },

Callers

nothing calls this directly

Calls 5

writeToOutputFunction · 0.85
JoinMethod · 0.80
EqualMethod · 0.80
ErrorfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected