-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed all uses of path to path/filepath to get cross-platform compa…
…tibility. Also fixed tests to work on windows as well.
- Loading branch information
Showing
14 changed files
with
194 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package osutil | ||
|
||
import ( | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
// MakeValidRegexPath takes a path and makes it into a valid regex string | ||
func MakeValidRegexPath(path string) string { | ||
return strings.Replace(filepath.FromSlash(path), "\\", "\\\\", -1) | ||
} | ||
|
||
// GetNotADirErrorMsg returns the error message given if an action is | ||
// performed on a non-existant directory. | ||
func GetNotADirErrorMsg() string { | ||
if runtime.GOOS == "windows" { | ||
return "The system cannot find the path specified." | ||
} | ||
return "not a directory" | ||
} | ||
|
||
// GetNoSuchFileOrDirErrorMsg returns the error message given if an action is | ||
// performed on a non-existant file or directory. | ||
func GetNoSuchFileOrDirErrorMsg() string { | ||
if runtime.GOOS == "windows" { | ||
return "The system cannot find the file specified." | ||
} | ||
return "no such file or directory" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package osutil_test | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/palantir/pkg/osutil" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestValidRegexPath(t *testing.T) { | ||
currentAbs, err := filepath.Abs(".") | ||
require.NoError(t, err) | ||
|
||
fmtString := `here is a path: %s with some text after` | ||
myRegexDef := fmt.Sprintf( | ||
"^"+fmtString+"$", | ||
osutil.MakeValidRegexPath(currentAbs), | ||
) | ||
|
||
assert.Regexp(t, regexp.MustCompile(myRegexDef), fmt.Sprintf(fmtString, currentAbs)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.