config/module: file paths require pwd

This commit is contained in:
Mitchell Hashimoto 2014-09-14 19:28:18 -07:00
parent a35a9262d4
commit 6eee9fbcb3
2 changed files with 33 additions and 0 deletions

View File

@ -16,6 +16,11 @@ func (d *FileDetector) Detect(src, pwd string) (string, bool, error) {
// Make sure we're using "/" even on Windows. URLs are "/"-based.
src = filepath.ToSlash(src)
if !filepath.IsAbs(src) {
if pwd == "" {
return "", true, fmt.Errorf(
"relative paths require a module with a pwd")
}
src = filepath.Join(pwd, src)
}

View File

@ -30,3 +30,31 @@ func TestFileDetector(t *testing.T) {
}
}
}
func TestFileDetector_noPwd(t *testing.T) {
cases := []struct {
Input string
Output string
Err bool
}{
{"./foo", "", true},
{"foo", "", true},
{"/foo", "file:///foo", false},
}
pwd := ""
f := new(FileDetector)
for i, tc := range cases {
output, ok, err := f.Detect(tc.Input, pwd)
if (err != nil) != tc.Err {
t.Fatalf("%d: err: %s", i, err)
}
if !ok {
t.Fatal("not ok")
}
if output != tc.Output {
t.Fatalf("%d: bad: %#v", i, output)
}
}
}