config/module: file paths require pwd
This commit is contained in:
parent
a35a9262d4
commit
6eee9fbcb3
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue