grim/convey

Parents 8dda30fb29f3
Children 675764a3a950
Special case '.' to keep compatibility and clean up the TestTraversed test
--- a/path/path.go Wed Dec 27 02:12:47 2017 -0600
+++ b/path/path.go Wed Dec 27 02:27:09 2017 -0600
@@ -27,6 +27,10 @@
// Traverses check whether path traverses outside of root. Returns error if
// root is traversed.
func Traverses(root, path string) (string, error) {
+ if path == "." {
+ return ".", nil
+ }
+
if !filepath.IsAbs(path) {
path = filepath.Join(root, path)
}
--- a/path/path_test.go Wed Dec 27 02:12:47 2017 -0600
+++ b/path/path_test.go Wed Dec 27 02:27:09 2017 -0600
@@ -18,8 +18,8 @@
package path
import (
+ "fmt"
"os"
- "path/filepath"
"testing"
"github.com/aphistic/sweet"
@@ -45,16 +45,15 @@
"..": true,
".": false,
"bar": false,
- "foo/../baz": true,
+ "foo/../baz": false,
}
wd, err := os.Getwd()
Expect(err).To(BeNil())
- wd = filepath.Join(wd, "foo")
-
for path, res := range tests {
- _, err := Traverses(wd, path)
+ fmt.Printf("testing %s\n", path)
+ _, err := TraversesNonExistent(wd, path)
if res {
Expect(err).ToNot(BeNil())
} else {
@@ -62,3 +61,12 @@
}
}
}
+
+func (s *pathSuite) TestDot(t sweet.T) {
+ wd, err := os.Getwd()
+ Expect(err).To(BeNil())
+
+ path, err := Traverses(wd, ".")
+ Expect(path).To(Equal("."))
+ Expect(err).To(BeNil())
+}