MCPcopy Index your code
hub / github.com/cli/cli / Test_NewCmdReadDir

Function Test_NewCmdReadDir

pkg/cmd/repo/read-dir/read_dir_test.go:93–160  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func Test_NewCmdReadDir(t *testing.T) {
94 tests := []struct {
95 name string
96 args string
97 wantOpts ReadDirOptions
98 wantErr string
99 }{
100 {
101 name: "no args lists root",
102 args: "",
103 wantOpts: ReadDirOptions{
104 Path: "",
105 },
106 },
107 {
108 name: "path argument",
109 args: "pkg/cmd",
110 wantOpts: ReadDirOptions{
111 Path: "pkg/cmd",
112 },
113 },
114 {
115 name: "ref flag",
116 args: "docs --ref v1.2.3",
117 wantOpts: ReadDirOptions{
118 Path: "docs",
119 Ref: "v1.2.3",
120 },
121 },
122 {
123 name: "too many arguments",
124 args: "a b",
125 wantErr: "accepts at most 1 arg(s), received 2",
126 },
127 }
128
129 for _, tt := range tests {
130 t.Run(tt.name, func(t *testing.T) {
131 ios, _, _, _ := iostreams.Test()
132 f := &cmdutil.Factory{
133 IOStreams: ios,
134 }
135
136 var gotOpts *ReadDirOptions
137 cmd := NewCmdReadDir(f, func(opts *ReadDirOptions) error {
138 gotOpts = opts
139 return nil
140 })
141
142 argv, err := shlex.Split(tt.args)
143 require.NoError(t, err)
144 cmd.SetArgs(argv)
145 cmd.SetIn(&bytes.Buffer{})
146 cmd.SetOut(io.Discard)
147 cmd.SetErr(io.Discard)
148
149 _, err = cmd.ExecuteC()
150 if tt.wantErr != "" {

Callers

nothing calls this directly

Calls 6

TestFunction · 0.92
NewCmdReadDirFunction · 0.85
ContainsMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected