Skip to content

Commit c40d42d

Browse files
committed
filestore util: refactor and clean up tests
License: MIT Signed-off-by: Kevin Atkinson <[email protected]>
1 parent 1131065 commit c40d42d

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

test/sharness/t0271-filestore-utils.sh

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ test_description="Test out the filestore nocopy functionality"
88

99
. lib/test-lib.sh
1010

11+
test_init_filestore() {
12+
test_expect_success "clean up old node" '
13+
rm -rf "$IPFS_PATH" mountdir ipfs ipns
14+
'
15+
16+
test_init_ipfs
17+
18+
test_expect_success "enable filestore config setting" '
19+
ipfs config --json Experimental.FilestoreEnabled true
20+
'
21+
}
1122

1223
test_init_dataset() {
1324
test_expect_success "create a dataset" '
@@ -19,6 +30,11 @@ test_init_dataset() {
1930
'
2031
}
2132

33+
test_init() {
34+
test_init_filestore
35+
test_init_dataset
36+
}
37+
2238
EXPHASH="QmRueCuPMYYvdxWz1vWncF7wzCScEx4qasZXo5aVBb1R4V"
2339

2440
cat <<EOF > ls_expect
@@ -68,11 +84,16 @@ test_filestore_adds() {
6884
'
6985
}
7086

71-
test_filestore_verify() {
87+
# check that the filestore is in a clean state
88+
test_filestore_state() {
7289
test_expect_success "ipfs filestore verify' output looks good'" '
7390
ipfs filestore verify | LC_ALL=C sort > verify_actual
7491
test_cmp verify_expect verify_actual
7592
'
93+
}
94+
95+
test_filestore_verify() {
96+
test_filestore_state
7697

7798
test_expect_success "'ipfs filestore verify HASH' works" '
7899
ipfs filestore verify $FILE1_HASH > verify_actual &&
@@ -113,16 +134,19 @@ test_filestore_verify() {
113134
ipfs filestore verify > verify_actual &&
114135
grep changed verify_actual | grep -q somedir/file3
115136
'
137+
138+
# reset the state for the next test
139+
test_init_dataset
116140
}
117141

118-
cat <<EOF > dups_expect
119-
$FILE1_HASH
120-
EOF
142+
test_filestore_dups_and_rm() {
143+
# make sure the filestore is in a clean state
144+
test_filestore_state
121145

122-
test_filestore_dups_rm() {
123146
test_expect_success "'ipfs filestore dups'" '
124147
ipfs add --raw-leaves somedir/file1 &&
125148
ipfs filestore dups > dups_actual &&
149+
echo "$FILE1_HASH" > dups_expect
126150
test_cmp dups_expect dups_actual
127151
'
128152

@@ -149,36 +173,23 @@ test_filestore_dups_rm() {
149173
'
150174
}
151175

152-
init_ipfs_filestore() {
153-
test_expect_success "clean up old node" '
154-
rm -rf "$IPFS_PATH" mountdir ipfs ipns
155-
'
156-
157-
test_init_ipfs
158-
159-
test_expect_success "enable filestore config setting" '
160-
ipfs config --json Experimental.FilestoreEnabled true
161-
'
162-
}
163-
164-
test_init_dataset
176+
#
177+
# No daemon
178+
#
165179

166-
init_ipfs_filestore
180+
test_init
167181

168182
test_filestore_adds
169183

170184
test_filestore_verify
171185

172-
test_filestore_dups_rm
186+
test_filestore_dups_and_rm
173187

174-
echo "WORKING DIR"
175-
echo "IPFS PATH = " $IPFS_PATH
176-
pwd
177-
178-
179-
test_init_dataset
188+
#
189+
# With daemon
190+
#
180191

181-
init_ipfs_filestore
192+
test_init
182193

183194
# must be in offline mode so tests of retrieving non-exist blocks
184195
# don't hang
@@ -188,7 +199,7 @@ test_filestore_adds
188199

189200
test_filestore_verify
190201

191-
test_filestore_dups_rm
202+
test_filestore_dups_and_rm
192203

193204
test_kill_ipfs_daemon
194205

0 commit comments

Comments
 (0)