mirror of https://github.com/spf13/afero.git
38 lines
739 B
Go
38 lines
739 B
Go
package afero
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestBasePath(t *testing.T) {
|
|
baseFs := &MemMapFs{}
|
|
baseFs.MkdirAll("/base/path/tmp", 0777)
|
|
bp := NewBasePathFs(baseFs, "/base/path")
|
|
|
|
if _, err := bp.Create("/tmp/foo"); err != nil {
|
|
t.Errorf("Failed to set real path")
|
|
}
|
|
|
|
if fh, err := bp.Create("../tmp/bar"); err == nil {
|
|
t.Errorf("succeeded in creating %s ...", fh.Name())
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|