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

Function TestReadMarkdownBodyFile

pkg/cmdutil/file_input_test.go:28–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26func (r *stdinReader) Close() error { return nil }
27
28func TestReadMarkdownBodyFile(t *testing.T) {
29 tests := []struct {
30 name string
31 files map[string]string
32 path string
33 stdin string
34 wantContent string
35 wantDir string
36 wantErrIs error
37 }{
38 {
39 name: "a file in the working directory",
40 files: map[string]string{"body.md": "![login](./login.png)\n"},
41 path: "body.md",
42 wantContent: "![login](./login.png)\n",
43 wantDir: ".",
44 },
45 {
46 name: "a file in another directory",
47 files: map[string]string{"docs/body.md": "![login](./login.png)\n"},
48 path: "docs/body.md",
49 wantContent: "![login](./login.png)\n",
50 wantDir: "docs",
51 },
52 {
53 name: "standard input has no directory",
54 path: "-",
55 stdin: "![login](./login.png)\n",
56 wantContent: "![login](./login.png)\n",
57 wantDir: "",
58 },
59 {
60 name: "standard input is only read for -",
61 files: map[string]string{"body.md": "From the file\n"},
62 path: "body.md",
63 stdin: "From standard input\n",
64 wantContent: "From the file\n",
65 wantDir: ".",
66 },
67 {
68 name: "a missing file",
69 path: "docs/missing.md",
70 wantErrIs: fs.ErrNotExist,
71 },
72 }
73
74 for _, tt := range tests {
75 t.Run(tt.name, func(t *testing.T) {
76 t.Chdir(t.TempDir())
77 for path, content := range tt.files {
78 require.NoError(t, os.MkdirAll(filepath.Dir(path), 0755))
79 require.NoError(t, os.WriteFile(path, []byte(content), 0644))
80 }
81 stdin := &stdinReader{Reader: strings.NewReader(tt.stdin)}
82
83 content, dir, err := ReadMarkdownBodyFile(tt.path, stdin)
84
85 assert.Equal(t, tt.path == "-", stdin.read, "standard input is read only for -")

Callers

nothing calls this directly

Calls 6

ReadMarkdownBodyFileFunction · 0.85
MkdirAllMethod · 0.80
WriteFileMethod · 0.80
EqualMethod · 0.80
EmptyMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected