forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_blocks_test.go
164 lines (153 loc) · 3.84 KB
/
multi_blocks_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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
// These tests all do one conflict-free operation while a user is unstaged.
package test
import "testing"
// alice writes a multi-block file, and bob reads it
func TestWriteMultiblockFile(t *testing.T) {
test(t,
blockSize(20), users("alice", "bob"),
as(alice,
write("a/b", ntimesString(15, "0123456789")),
),
as(bob,
read("a/b", ntimesString(15, "0123456789")),
),
)
}
func TestSwitchToMultiblockFile(t *testing.T) {
test(t,
blockSize(20), users("alice", "bob"),
as(alice,
// Fill up the first block (a desired encrypted block size
// of 20 ends up with a plaintext size of 12).
write("a/b", ntimesString(3, "0123")),
// Then append to the end of the file to force a split.
pwriteBS("a/b", []byte(ntimesString(3, "0123")), 12),
),
as(bob,
read("a/b", ntimesString(6, "0123")),
),
)
}
// alice writes a file, and bob overwrites it with a multi-block file
func TestOverwriteMultiblockFile(t *testing.T) {
test(t,
blockSize(20), users("alice", "bob"),
as(alice,
write("a/b", "hello"),
),
as(bob,
write("a/b", ntimesString(15, "0123456789")),
),
as(alice,
read("a/b", ntimesString(15, "0123456789")),
),
as(bob,
read("a/b", ntimesString(15, "0123456789")),
),
)
}
// bob removes a multiblock file written by alice (checks that state
// is cleaned up)
func TestRmMultiblockFile(t *testing.T) {
test(t,
blockSize(20), users("alice", "bob"),
as(alice,
write("a/b", ntimesString(15, "0123456789")),
),
as(bob,
read("a/b", ntimesString(15, "0123456789")),
rm("a/b"),
),
as(alice,
lsdir("a/", m{}),
),
)
}
// bob renames something over a multiblock file written by alice
// (checks that state is cleaned up)
func TestRenameOverMultiblockFile(t *testing.T) {
test(t,
blockSize(20), users("alice", "bob"),
as(alice,
write("a/b", ntimesString(15, "0123456789")),
write("a/c", "hello"),
),
as(bob,
read("a/b", ntimesString(15, "0123456789")),
read("a/c", "hello"),
rename("a/c", "a/b"),
),
as(alice,
read("a/b", "hello"),
lsdir("a/", m{"b": "FILE"}),
),
)
}
// bob writes a second copy of a multiblock file written by alice
// (tests dedupping, but hard to verify that precisely here).
func TestCopyMultiblockFile(t *testing.T) {
test(t,
blockSize(20), users("alice", "bob"),
as(alice,
write("a/b", ntimesString(15, "0123456789")),
),
as(bob,
read("a/b", ntimesString(15, "0123456789")),
write("a/c", ntimesString(15, "0123456789")),
),
as(alice,
read("a/b", ntimesString(15, "0123456789")),
read("a/c", ntimesString(15, "0123456789")),
rm("a/b"),
),
as(bob,
read("a/c", ntimesString(15, "0123456789")),
),
)
}
// Test that we can make a big file, delete it, then make it
// again. Regression for KBFS-700.
func TestMakeDeleteAndMakeMultiBlockFile(t *testing.T) {
test(t,
blockSize(20), users("alice", "bob"),
as(alice,
write("a/b", ntimesString(15, "0123456789")),
),
as(bob,
read("a/b", ntimesString(15, "0123456789")),
rm("a/b"),
write("a/b2", ntimesString(15, "0123456789")),
),
as(alice,
read("a/b2", ntimesString(15, "0123456789")),
),
)
}
// When block changes are unembedded, make sure other users can read
// and apply them.
func TestReadUnembeddedBlockChanges(t *testing.T) {
test(t,
blockChangeSize(5), users("alice", "bob"),
as(alice,
write("a/b", "hello"),
),
as(bob,
read("a/b", "hello"),
write("a/c", "hello2"),
write("a/d", "hello3"),
write("a/e", "hello4"),
write("a/f", "hello5"),
),
as(alice,
lsdir("a", m{"b": "FILE", "c": "FILE", "d": "FILE", "e": "FILE", "f": "FILE"}),
read("a/b", "hello"),
read("a/c", "hello2"),
read("a/d", "hello3"),
read("a/e", "hello4"),
read("a/f", "hello5"),
),
)
}