2015-12-30 10:16:22 +03:00
|
|
|
package afero
|
|
|
|
|
|
|
|
import (
|
2016-01-12 08:34:15 +03:00
|
|
|
"os"
|
2016-01-11 23:30:26 +03:00
|
|
|
"testing"
|
2015-12-30 10:16:22 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBasePath(t *testing.T) {
|
2016-01-11 23:30:26 +03:00
|
|
|
baseFs := &MemMapFs{}
|
|
|
|
baseFs.MkdirAll("/base/path/tmp", 0777)
|
2016-01-12 05:41:03 +03:00
|
|
|
bp := NewBasePathFs(baseFs, "/base/path")
|
2015-12-30 10:16:22 +03:00
|
|
|
|
2016-01-11 23:30:26 +03:00
|
|
|
if _, err := bp.Create("/tmp/foo"); err != nil {
|
|
|
|
t.Errorf("Failed to set real path")
|
|
|
|
}
|
2015-12-30 10:16:22 +03:00
|
|
|
|
2016-01-11 23:30:26 +03:00
|
|
|
if fh, err := bp.Create("../tmp/bar"); err == nil {
|
|
|
|
t.Errorf("succeeded in creating %s ...", fh.Name())
|
|
|
|
}
|
2015-12-30 10:16:22 +03:00
|
|
|
}
|
2016-01-12 08:34:15 +03:00
|
|
|
|
|
|
|
func TestBasePathRoot(t *testing.T) {
|
|
|
|
baseFs := &MemMapFs{}
|
|
|
|
baseFs.MkdirAll("/base/path/foo/baz", 0777)
|
|
|
|
baseFs.MkdirAll("/base/path/boo/", 0777)
|
|
|
|
bp := NewBasePathFs(baseFs, "/base/path")
|
|
|
|
|
|
|
|
rd, err := ReadDir(bp, string(os.PathSeparator))
|
|
|
|
|
|
|
|
if len(rd) != 2 {
|
|
|
|
t.Errorf("base path doesn't respect root")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|