8 "github.com/stretchr/testify/require"
11func TestListDirectory(t *testing.T) {
14 testFiles := map[string]string{
15 "regular.txt": "content",
16 ".hidden": "hidden content",
17 ".gitignore": ".*\n*.log\n",
18 "subdir/file.go": "package main",
19 "subdir/.another": "more hidden",
20 "build.log": "build output",
23 for name, content := range testFiles {
24 fp := filepath.Join(tmp, name)
25 dir := filepath.Dir(fp)
26 require.NoError(t, os.MkdirAll(dir, 0o755))
27 require.NoError(t, os.WriteFile(fp, []byte(content), 0o644))
30 t.Run("no limit", func(t *testing.T) {
31 files, truncated, err := ListDirectory(tmp, nil, -1, -1)
32 require.NoError(t, err)
33 require.False(t, truncated)
34 require.Len(t, files, 4)
35 require.ElementsMatch(t, []string{
40 }, relPaths(t, files, tmp))
42 t.Run("limit", func(t *testing.T) {
43 files, truncated, err := ListDirectory(tmp, nil, -1, 2)
44 require.NoError(t, err)
45 require.True(t, truncated)
46 require.Len(t, files, 2)
50func relPaths(tb testing.TB, in []string, base string) []string {
52 out := make([]string, 0, len(in))
53 for _, p := range in {
54 rel, err := filepath.Rel(base, p)
55 require.NoError(tb, err)
56 out = append(out, filepath.ToSlash(rel))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list