-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdirs_test.go
75 lines (54 loc) · 1.43 KB
/
dirs_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
package freezer
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/uw-labs/straw"
)
func TestSeqToPath(t *testing.T) {
assert := assert.New(t)
assert.Equal("/foo/00/00/00/00/00/00/01", seqToPath("/foo", 1))
assert.Equal("/foo/99/99/99/99/99/99/99", seqToPath("/foo", 99999999999999))
}
func TestFindLatestEmpty(t *testing.T) {
assert := assert.New(t)
ss, _ := straw.Open("mem://")
latest, err := nextSequence(ss, "/foo/")
assert.NoError(err)
assert.Equal(0, latest)
}
func TestNotADir(t *testing.T) {
assert := assert.New(t)
ss, _ := straw.Open("mem://")
err := straw.MkdirAll(ss, seqToPath("/foo/", 0), 0777)
assert.NoError(err)
wc, err := ss.CreateWriteCloser("/foo/00/bar")
_, err = wc.Write([]byte{1})
assert.NoError(err)
assert.NoError(wc.Close())
seq2, err := nextSequence(ss, "/foo/")
assert.EqualError(err, "'bar' is not a directory")
assert.Equal(-1, seq2)
}
func TestFindLatest(t *testing.T) {
assert := assert.New(t)
ss, _ := straw.Open("mem://")
for i := 0; i < 12345; i++ {
path := seqToPath("/foo/", i)
dir := filepath.Dir(path)
straw.MkdirAll(ss, dir, 0755)
rc, err := ss.CreateWriteCloser(path)
if err != nil {
t.Fatal(err)
}
if _, err := rc.Write([]byte{0}); err != nil {
t.Fatal(err)
}
if err := rc.Close(); err != nil {
t.Fatal(err)
}
}
latest, err := nextSequence(ss, "/foo/")
assert.NoError(err)
assert.Equal(12345, latest)
}