aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/fileutils.go10
-rw-r--r--utils/fileutils_test.go15
2 files changed, 25 insertions, 0 deletions
diff --git a/utils/fileutils.go b/utils/fileutils.go
new file mode 100644
index 0000000..6c269ca
--- /dev/null
+++ b/utils/fileutils.go
@@ -0,0 +1,10 @@
+package utils
+
+import (
+ "path/filepath"
+ "strings"
+)
+
+func TrimTrailingSeparator(path string) string {
+ return strings.TrimSuffix(path, string(filepath.Separator))
+}
diff --git a/utils/fileutils_test.go b/utils/fileutils_test.go
new file mode 100644
index 0000000..176d856
--- /dev/null
+++ b/utils/fileutils_test.go
@@ -0,0 +1,15 @@
+package utils
+
+import (
+ "path/filepath"
+ "testing"
+)
+
+func TestTrimTrailingSeparator(t *testing.T) {
+ if TrimTrailingSeparator("test"+string(filepath.Separator)) != "test" {
+ t.Error("Seprator should have been trimmed")
+ }
+ if TrimTrailingSeparator("test") != "test" {
+ t.Error("Path should not have changed")
+ }
+}