Skip to content

Commit

Permalink
✅ chore(tests): fix some tests error on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Mar 18, 2023
1 parent c72adcb commit 78ded57
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Run unit tests
# run: go test -v -cover ./...
# must add " for profile.cov on Windows OS
run: go test -v -coverprofile="profile.cov" ./...
run: go test -coverprofile="profile.cov" ./...

- name: Send coverage
uses: shogo82148/actions-goveralls@v1
Expand Down
10 changes: 9 additions & 1 deletion fsutil/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ func IsFile(path string) bool {
}

// IsAbsPath is abs path.
func IsAbsPath(aPath string) bool { return filepath.IsAbs(aPath) }
func IsAbsPath(aPath string) bool {
if len(aPath) > 0 {
if aPath[0] == '/' {
return true
}
return filepath.IsAbs(aPath)
}
return false
}

// ImageMimeTypes refer net/http package
var ImageMimeTypes = map[string]string{
Expand Down
2 changes: 2 additions & 0 deletions fsutil/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func TestIsDir(t *testing.T) {

func TestIsAbsPath(t *testing.T) {
assert.True(t, fsutil.IsAbsPath("/data/some.txt"))
assert.False(t, fsutil.IsAbsPath(""))
assert.False(t, fsutil.IsAbsPath("some.txt"))
assert.NoErr(t, fsutil.DeleteIfFileExist("/not-exist"))
}

Expand Down
8 changes: 3 additions & 5 deletions fsutil/fsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,15 @@ func UnixPath(path string) string {
return strings.ReplaceAll(path, "\\", "/")
}

// ToAbsPath convert process.
// ToAbsPath convert process. will expand home dir
//
// TIP: will don't check path
func ToAbsPath(p string) string {
if len(p) == 0 {
return ""
}
if filepath.IsAbs(p) {
if len(p) == 0 || IsAbsPath(p) {
return p
}

// expand home dir
if p[0] == '~' {
return comfunc.ExpandHome(p)
}
Expand Down

0 comments on commit 78ded57

Please sign in to comment.