-
Notifications
You must be signed in to change notification settings - Fork 5
/
folder_sink_test.go
104 lines (87 loc) · 1.8 KB
/
folder_sink_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
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
package savior_test
import (
"io/ioutil"
"path/filepath"
"testing"
"github.com/itchio/savior"
"github.com/stretchr/testify/assert"
)
func Test_FolderSink(t *testing.T) {
assert := assert.New(t)
dir, err := ioutil.TempDir("", "foldersink-test")
tmust(t, err)
fs := &savior.FolderSink{
Directory: dir,
}
entry := &savior.Entry{
Kind: savior.EntryKindFile,
Mode: 0644,
CanonicalPath: "secret",
WriteOffset: 0,
}
{
w, err := fs.GetWriter(entry)
tmust(t, err)
_, err = w.Write([]byte("foobar"))
tmust(t, err)
err = w.Close()
tmust(t, err)
}
entry.WriteOffset = 1
{
w, err := fs.GetWriter(entry)
tmust(t, err)
_, err = w.Write([]byte("ee"))
tmust(t, err)
err = w.Close()
tmust(t, err)
}
bs, err := ioutil.ReadFile(filepath.Join(dir, "secret"))
tmust(t, err)
s := string(bs)
assert.EqualValues("fee", s)
}
func Test_FolderSinkIgnorePaths(t *testing.T) {
assert := assert.New(t)
dir, err := ioutil.TempDir("", "foldersink-test")
tmust(t, err)
fs := &savior.FolderSink{
Directory: dir,
}
entries := []*savior.Entry{
&savior.Entry{
Kind: savior.EntryKindFile,
Mode: 0644,
CanonicalPath: "Icon\r",
WriteOffset: 0,
},
&savior.Entry{
Kind: savior.EntryKindFile,
Mode: 0644,
CanonicalPath: "Foobar",
WriteOffset: 0,
},
}
for _, entry := range entries {
{
w, err := fs.GetWriter(entry)
tmust(t, err)
_, err = w.Write([]byte("foobar"))
tmust(t, err)
err = w.Close()
tmust(t, err)
}
}
files, err := ioutil.ReadDir(dir)
tmust(t, err)
assert.Equal(1, len(files))
}
// tmust shows a complete error stack and fails a test immediately
// if err is non-nil
func tmust(t *testing.T, err error) {
if err != nil {
t.Helper()
t.Errorf("%+v", err)
t.FailNow()
}
}