-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_test.go
More file actions
108 lines (95 loc) · 2.49 KB
/
Copy pathfile_test.go
File metadata and controls
108 lines (95 loc) · 2.49 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package sprocess_test
import (
"bytes"
. "github.com/hyperboloide/sprocess"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io"
"os"
"path/filepath"
)
var _ = Describe("File", func() {
testBin := genBlob(1 << 22)
Context("simple file", func() {
data := NewData()
id := GenId()
f := &File{
Dir: tmpDir(),
Name: "file",
}
It("should Write", func() {
Ω(f.Start()).To(BeNil())
w, err := f.NewWriter(id, data)
Ω(err).To(BeNil())
Ω(w).ToNot(BeNil())
l, err := io.Copy(w, bytes.NewReader(testBin))
w.Close()
Ω(err).To(BeNil())
Ω(len(testBin) == int(l)).To(BeTrue())
})
It("should read", func() {
r, err := f.NewReader(id, data)
Ω(err).To(BeNil())
Ω(r).ToNot(BeNil())
out1 := new(bytes.Buffer)
l, err := io.Copy(out1, r)
Ω(err).To(BeNil())
r.Close()
Ω(len(testBin) == int(l)).To(BeTrue())
Ω(bytes.Equal(testBin, out1.Bytes())).To(BeTrue())
})
It("should delete", func() {
Ω(f.Delete(id, data)).To(BeNil())
_, err := os.Stat(f.Dir + "/" + id)
Ω(os.IsNotExist(err)).To(BeTrue())
})
It("should not write with sub path", func() {
Ω(f.Start()).To(BeNil())
_, err := f.NewWriter("some/path/"+id, data)
Ω(err).ToNot(BeNil())
})
})
Context("with path", func() {
data := NewData()
id := GenId()
path := "some/example/path/" + id
f := &File{
Dir: tmpDir(),
AllowSub: true,
RemoveEmpty: true,
Name: "file",
}
It("should Write", func() {
Ω(f.Start()).To(BeNil())
w, err := f.NewWriter(path, data)
Ω(err).To(BeNil())
Ω(w).ToNot(BeNil())
l, err := io.Copy(w, bytes.NewReader(testBin))
w.Close()
Ω(err).To(BeNil())
Ω(len(testBin) == int(l)).To(BeTrue())
})
It("should read", func() {
r, err := f.NewReader(path, data)
Ω(err).To(BeNil())
Ω(r).ToNot(BeNil())
out1 := new(bytes.Buffer)
l, err := io.Copy(out1, r)
Ω(err).To(BeNil())
r.Close()
Ω(len(testBin) == int(l)).To(BeTrue())
Ω(bytes.Equal(testBin, out1.Bytes())).To(BeTrue())
})
It("should delete", func() {
Ω(f.Delete(path, data)).To(BeNil())
_, err := os.Stat(filepath.Join(f.Dir + "/some/example/path" + id))
Ω(os.IsNotExist(err)).To(BeTrue())
_, err = os.Stat(filepath.Join(f.Dir + "/some/example/path"))
Ω(os.IsNotExist(err)).To(BeTrue())
_, err = os.Stat(filepath.Join(f.Dir + "/some/example"))
Ω(os.IsNotExist(err)).To(BeTrue())
_, err = os.Stat(filepath.Join(f.Dir + "/some"))
Ω(os.IsNotExist(err)).To(BeTrue())
})
})
})