(t *testing.T)
| 160 | } |
| 161 | |
| 162 | func Test_readDirRun(t *testing.T) { |
| 163 | tests := []struct { |
| 164 | name string |
| 165 | tty bool |
| 166 | opts ReadDirOptions |
| 167 | httpStubs func(*httpmock.Registry) |
| 168 | jsonFields []string |
| 169 | wantOut string |
| 170 | wantStderr string |
| 171 | wantErrMsg string |
| 172 | }{ |
| 173 | { |
| 174 | name: "base repo resolution error", |
| 175 | opts: ReadDirOptions{ |
| 176 | BaseRepo: func() (ghrepo.Interface, error) { |
| 177 | return nil, errors.New("some error") |
| 178 | }, |
| 179 | }, |
| 180 | wantErrMsg: "some error. Run this command from within a git repository, or use the `--repo` flag to specify one", |
| 181 | }, |
| 182 | { |
| 183 | name: "root listing (tty)", |
| 184 | tty: true, |
| 185 | httpStubs: func(reg *httpmock.Registry) { |
| 186 | reg.Register( |
| 187 | httpmock.GraphQL(`query RepoReadDir\b`), |
| 188 | httpmock.StringResponse(compactJSON(` |
| 189 | { |
| 190 | "data":{"repository":{"object":{ |
| 191 | "__typename":"Tree", |
| 192 | "oid":"tree-sha", |
| 193 | "id":"tree-id", |
| 194 | "entries":[ |
| 195 | {"name":".github","path":".github","nameRaw":".github","pathRaw":".github","type":"tree","mode":16384,"oid":"oid-github","size":0,"submodule":null}, |
| 196 | {"name":"README.md","path":"README.md","nameRaw":"README.md","pathRaw":"README.md","type":"blob","mode":33188,"oid":"oid-readme","size":2048,"submodule":null}, |
| 197 | {"name":"build.sh","path":"build.sh","nameRaw":"build.sh","pathRaw":"build.sh","type":"blob","mode":33261,"oid":"oid-build","size":512,"submodule":null}, |
| 198 | {"name":"latest","path":"latest","nameRaw":"latest","pathRaw":"latest","type":"blob","mode":40960,"oid":"oid-latest","size":18,"submodule":null}, |
| 199 | {"name":"vendor","path":"vendor","nameRaw":"vendor","pathRaw":"vendor","type":"commit","mode":57344,"oid":"oid-vendor","size":0,"submodule":null} |
| 200 | ] |
| 201 | }}} |
| 202 | }`)), |
| 203 | ) |
| 204 | }, |
| 205 | wantOut: heredoc.Doc(` |
| 206 | Showing 5 entries in OWNER/REPO |
| 207 | |
| 208 | TYPE NAME SIZE |
| 209 | dir .github - |
| 210 | file README.md 2.0 KB |
| 211 | file* build.sh 512 B |
| 212 | symlink latest 18 B |
| 213 | submodule vendor - |
| 214 | `), |
| 215 | }, |
| 216 | { |
| 217 | name: "single entry uses singular noun (tty)", |
| 218 | tty: true, |
| 219 | httpStubs: func(reg *httpmock.Registry) { |
nothing calls this directly
no test coverage detected