-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile_store_test.go
65 lines (49 loc) · 1.32 KB
/
file_store_test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package fuh_test
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/LyricTian/fuh"
. "github.com/smartystreets/goconvey/convey"
)
func TestFileStore(t *testing.T) {
basePath := "testdatas/"
Convey("file storage test", t, func() {
Convey("write data", func() {
store := fuh.NewFileStore()
buf := []byte("abc")
filename := filepath.Join(basePath, "write.txt")
err := store.Store(nil, filename, bytes.NewReader(buf), int64(len(buf)))
So(err, ShouldBeNil)
if err == nil {
defer os.Remove(filename)
}
file, err := os.Open(filename)
So(err, ShouldBeNil)
defer file.Close()
fbuf, err := ioutil.ReadAll(file)
So(err, ShouldBeNil)
So(string(fbuf), ShouldEqual, string(buf))
})
Convey("rewrite data", func() {
filename := filepath.Join(basePath, "rewrite.txt")
cfile, err := os.Create(filename)
So(err, ShouldBeNil)
defer os.Remove(filename)
cfile.Write([]byte("123"))
cfile.Close()
buf := []byte("abc")
store := &fuh.FileStore{Rewrite: true}
err = store.Store(nil, filename, bytes.NewReader(buf), int64(len(buf)))
So(err, ShouldBeNil)
ofile, err := os.Open(filename)
So(err, ShouldBeNil)
defer ofile.Close()
fbuf, err := ioutil.ReadAll(ofile)
So(err, ShouldBeNil)
So(string(fbuf), ShouldEqual, string(buf))
})
})
}