mirror of https://github.com/pkg/sftp.git
added File.Stat/fstat coverage
This commit is contained in:
parent
b4d8e6c537
commit
44d7769a0d
|
|
@ -522,7 +522,7 @@ func (f *File) ReadAt(b []byte, off int64) (int, error) {
|
|||
func (f *File) Stat() (os.FileInfo, error) {
|
||||
fi, err := f.c.fstat(f.handle)
|
||||
if err == nil {
|
||||
fi.name = f.path
|
||||
fi.name = path.Base(f.path)
|
||||
}
|
||||
return fi, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,6 +133,37 @@ func TestClientRead(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestClientFileStat(t *testing.T) {
|
||||
sftp, cmd := testClient(t)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
f, err := ioutil.TempFile("", "sftptest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(f.Name())
|
||||
|
||||
want, err := os.Lstat(f.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
f2, err := sftp.Open(f.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got, err := f2.Stat()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !sameFile(want, got) {
|
||||
t.Fatalf("Lstat(%q): want %#v, got %#v", f.Name(), want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func sameFile(want, got os.FileInfo) bool {
|
||||
return want.Name() == got.Name() &&
|
||||
want.Size() == got.Size()
|
||||
|
|
|
|||
Loading…
Reference in New Issue