Commit f980c761 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Strip slashes from prefixes in SwitchFileSystem.

parent 0a7304c1
......@@ -53,6 +53,8 @@ func NewSwitchFileSystem(fsMap []SwitchedFileSystem) *SwitchFileSystem {
me := &SwitchFileSystem{}
for _, inSwFs := range fsMap {
swFs := inSwFs
swFs.Prefix = strings.TrimLeft(swFs.Prefix, string(filepath.Separator))
swFs.Prefix = strings.TrimRight(swFs.Prefix, string(filepath.Separator))
me.fileSystems = append(me.fileSystems, &swFs)
}
sort.Sort(me.fileSystems)
......
......@@ -4,6 +4,25 @@ import (
"testing"
)
func TestSwitchFsSlash(t *testing.T) {
fsMap := []SwitchedFileSystem{
SwitchedFileSystem{Prefix: ""},
SwitchedFileSystem{Prefix:"/home"},
SwitchedFileSystem{Prefix:"usr/"},
}
sfs := NewSwitchFileSystem(fsMap)
for path, expectPrefix := range map[string]string {
"home/foo/bar": "home",
"usr/local": "usr",
} {
_, fs := sfs.findFileSystem(path)
if fs.Prefix != expectPrefix {
t.Errorf("Mismatch %s - '%s' != '%s'", path, fs.Prefix, expectPrefix)
}
}
}
func TestSwitchFs(t *testing.T) {
fsMap := []SwitchedFileSystem{
SwitchedFileSystem{Prefix: ""},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment