-
Notifications
You must be signed in to change notification settings - Fork 0
/
testfiledriver.go
51 lines (40 loc) · 1.01 KB
/
testfiledriver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package sftp
import (
"io"
"io/ioutil"
"os"
"path/filepath"
)
type TestFileDriver struct{}
func (d TestFileDriver) Stat(path string) (os.FileInfo, error) {
return os.Stat(path)
}
func (d TestFileDriver) ListDir(path string) ([]os.FileInfo, error) {
return ioutil.ReadDir(path)
}
func (d TestFileDriver) DeleteDir(path string) error {
return os.Remove(path)
}
func (d TestFileDriver) DeleteFile(path string) error {
return os.Remove(path)
}
func (d TestFileDriver) Rename(oldpath string, newpath string) error {
return os.Rename(oldpath, newpath)
}
func (d TestFileDriver) MakeDir(path string) error {
return os.Mkdir(path, 0755)
}
func (d TestFileDriver) GetFile(path string) (io.ReadCloser, error) {
f, err := os.Open(path)
return f, err
}
func (d TestFileDriver) PutFile(path string, r io.Reader) error {
bytes, err := ioutil.ReadAll(r)
if err != nil {
return err
}
return ioutil.WriteFile(path, bytes, 0755)
}
func (d TestFileDriver) RealPath(path string) string {
return filepath.Clean("/" + path)
}