Fix unittest and repo create bug (#33061)

1. `StatDir` was not right, fix the FIXME
2. Clarify the test cases for `IsUsableRepoName`
3. Fix regression bug in `repo-new.ts`

Fix #33060
This commit is contained in:
wxiaoguang 2024-12-31 18:45:05 +08:00 committed by GitHub
parent 58c092cfea
commit a0853e2278
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 81 additions and 83 deletions

View file

@ -5,10 +5,12 @@ package util
import (
"net/url"
"os"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFileURLToPath(t *testing.T) {
@ -210,3 +212,21 @@ func TestCleanPath(t *testing.T) {
assert.Equal(t, c.expected, FilePathJoinAbs(c.elems[0], c.elems[1:]...), "case: %v", c.elems)
}
}
func TestListDirRecursively(t *testing.T) {
tmpDir := t.TempDir()
_ = os.WriteFile(tmpDir+"/.config", nil, 0o644)
_ = os.Mkdir(tmpDir+"/d1", 0o755)
_ = os.WriteFile(tmpDir+"/d1/f-d1", nil, 0o644)
_ = os.Mkdir(tmpDir+"/d1/s1", 0o755)
_ = os.WriteFile(tmpDir+"/d1/s1/f-d1s1", nil, 0o644)
_ = os.Mkdir(tmpDir+"/d2", 0o755)
res, err := ListDirRecursively(tmpDir, &ListDirOptions{IncludeDir: true})
require.NoError(t, err)
assert.ElementsMatch(t, []string{".config", "d1/", "d1/f-d1", "d1/s1/", "d1/s1/f-d1s1", "d2/"}, res)
res, err = ListDirRecursively(tmpDir, &ListDirOptions{SkipCommonHiddenNames: true})
require.NoError(t, err)
assert.ElementsMatch(t, []string{"d1/f-d1", "d1/s1/f-d1s1"}, res)
}