lib/fs: Evaluate root when watching not on fs creation (fixes #5043) (#5105)

This commit is contained in:
Simon Frei
2018-08-11 22:24:36 +02:00
committed by Jakob Borg
parent b37c05c6b8
commit e20679afe1
5 changed files with 83 additions and 53 deletions

View File

@@ -12,6 +12,7 @@ import (
"path/filepath"
"runtime"
"sort"
"strings"
"testing"
"time"
)
@@ -449,3 +450,35 @@ func TestRooted(t *testing.T) {
}
}
}
func TestNewBasicFilesystem(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("non-windows root paths")
}
testCases := []struct {
input string
expectedRoot string
expectedURI string
}{
{"/foo/bar/baz", "/foo/bar/baz/", "/foo/bar/baz/"},
{"/foo/bar/baz/", "/foo/bar/baz/", "/foo/bar/baz/"},
{"", "/", "/"},
{"/", "/", "/"},
}
for _, testCase := range testCases {
fs := newBasicFilesystem(testCase.input)
if fs.root != testCase.expectedRoot {
t.Errorf("root %q != %q", fs.root, testCase.expectedRoot)
}
if fs.URI() != testCase.expectedURI {
t.Errorf("uri %q != %q", fs.URI(), testCase.expectedURI)
}
}
fs := newBasicFilesystem("relative/path")
if fs.root == "relative/path" || !strings.HasPrefix(fs.root, string(PathSeparator)) {
t.Errorf(`newBasicFilesystem("relative/path").root == %q, expected absolutification`, fs.root)
}
}