Skip to content

Commit d26a0a2

Browse files
jbenetwhyrusleeping
authored andcommitted
test/sharness: added more pinning tests
Pinning is currently broken. See issue #1051. This commit introduces a few more pinning tests. These are by no means exhaustive, but definitely surface the present problems going on. I believe these tests are correct, but not sure. Pushing them as failing so that pinning is fixed in this PR.
1 parent 2411de5 commit d26a0a2

File tree

1 file changed

+201
-0
lines changed

1 file changed

+201
-0
lines changed

test/sharness/t0081-repo-pinning.sh

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2014 Jeromy Johnson
4+
# MIT Licensed; see the LICENSE file in this repository.
5+
#
6+
7+
test_description="Test ipfs repo pinning"
8+
9+
. lib/test-lib.sh
10+
11+
test_init_ipfs
12+
test_launch_ipfs_daemon
13+
14+
15+
HASH_FILE6="QmRsBC3Y2G6VRPYGAVpZczx1W7Xw54MtM1NcLKTkn6rx3U"
16+
HASH_FILE5="QmaN3PtyP8DcVGHi3Q2Fcp7CfAFVcVXKddWbHoNvaA41zf"
17+
HASH_FILE4="QmV1aiVgpDknKQugrK59uBUbMrPnsQM1F9FXbFcfgEvUvH"
18+
HASH_FILE3="QmZrr4Pzqp3NnMzMfbMhNe7LghfoUFHVx7c9Po9GZrhKZ7"
19+
HASH_FILE2="QmSkjTornLY72QhmK9NvAz26815pTaoAL42rF8Qi3w2WBP"
20+
HASH_FILE1="QmbgX4aXhSSY88GHmPQ4roizD8wFwPX8jzTLjc8VAp89x4"
21+
HASH_DIR3="QmRsCaNBMkweZ9vHT5PJRd2TT9rtNKEKyuognCEVxZxF1H"
22+
HASH_DIR4="QmW98gV71Ns4bX7QbgWAqLiGF3SDC1JpveZSgBh4ExaSAd"
23+
HASH_DIR2="QmTUTQAgeVfughDSFukMZLbfGvetDJY7Ef5cDXkKK4abKC"
24+
HASH_DIR1="QmNyZVFbgvmzguS2jVMRb8PQMNcCMJrn9E3doDhBbcPNTY"
25+
26+
test_expect_success "'ipfs add dir' succeeds" '
27+
mkdir dir1 &&
28+
mkdir dir1/dir2 &&
29+
mkdir dir1/dir3 &&
30+
mkdir dir1/dir2/dir4 &&
31+
echo "some text 1" >dir1/file1 &&
32+
echo "some text 1" >dir1/dir2/file1 &&
33+
echo "some text 1" >dir1/dir2/dir4/file1 &&
34+
echo "some text 2" >dir1/file2 &&
35+
echo "some text 2" >dir1/dir3/file2 &&
36+
echo "some text 2" >dir1/dir2/dir4/file2 &&
37+
echo "some text 3" >dir1/file3 &&
38+
echo "some text 4" >dir1/dir2/file4 &&
39+
echo "some text 5" >dir1/dir3/file5 &&
40+
echo "some text 6" >dir1/dir2/dir4/file6 &&
41+
ipfs add -q -r dir1 | tail -n1 >actual1 &&
42+
echo "$HASH_DIR1" >expected1 &&
43+
test_cmp actual1 expected1
44+
'
45+
46+
test_expect_success "objects are there" '
47+
ipfs cat "$HASH_FILE6" >FILE6_a &&
48+
ipfs cat "$HASH_FILE5" >FILE5_a &&
49+
ipfs cat "$HASH_FILE4" >FILE4_a &&
50+
ipfs cat "$HASH_FILE3" >FILE3_a &&
51+
ipfs cat "$HASH_FILE2" >FILE2_a &&
52+
ipfs cat "$HASH_FILE1" >FILE1_a &&
53+
ipfs ls "$HASH_DIR3" >DIR3_a &&
54+
ipfs ls "$HASH_DIR4" >DIR4_a &&
55+
ipfs ls "$HASH_DIR2" >DIR2_a &&
56+
ipfs ls "$HASH_DIR1" >DIR1_a
57+
'
58+
59+
test_expect_success "added dir was pinned recursively" '
60+
ipfs pin ls -type=recursive >actual2 &&
61+
grep "$HASH_DIR1" actual2
62+
'
63+
64+
test_expect_success "rest were pinned indirectly" '
65+
ipfs pin ls -type=indirect >actual3 &&
66+
grep "$HASH_FILE6" actual3 &&
67+
grep "$HASH_FILE5" actual3 &&
68+
grep "$HASH_FILE4" actual3 &&
69+
grep "$HASH_FILE3" actual3 &&
70+
grep "$HASH_FILE2" actual3 &&
71+
grep "$HASH_FILE1" actual3 &&
72+
grep "$HASH_DIR3" actual3 &&
73+
grep "$HASH_DIR4" actual3 &&
74+
grep "$HASH_DIR2" actual3
75+
'
76+
77+
test_expect_success "added dir was NOT pinned indirectly" '
78+
test_must_fail grep "$HASH_DIR1" actual3
79+
'
80+
81+
test_expect_success "nothing is pinned directly" '
82+
ipfs pin ls -type=direct >actual4 &&
83+
test_must_be_empty actual4
84+
'
85+
86+
test_expect_success "'ipfs repo gc' succeeds" '
87+
ipfs repo gc >gc_out_actual &&
88+
test_must_be_empty gc_out_actual
89+
'
90+
91+
test_expect_success "objects are still there" '
92+
ipfs cat "$HASH_FILE6" >FILE6_b && test_cmp FILE6_a FILE6_b &&
93+
ipfs cat "$HASH_FILE5" >FILE5_b && test_cmp FILE5_a FILE5_b &&
94+
ipfs cat "$HASH_FILE4" >FILE4_b && test_cmp FILE4_a FILE4_b &&
95+
ipfs cat "$HASH_FILE3" >FILE3_b && test_cmp FILE3_a FILE3_b &&
96+
ipfs cat "$HASH_FILE2" >FILE2_b && test_cmp FILE2_a FILE2_b &&
97+
ipfs cat "$HASH_FILE1" >FILE1_b && test_cmp FILE1_a FILE1_b &&
98+
ipfs ls "$HASH_DIR3" >DIR3_b && test_cmp DIR3_a DIR3_b &&
99+
ipfs ls "$HASH_DIR4" >DIR4_b && test_cmp DIR4_a DIR4_b &&
100+
ipfs ls "$HASH_DIR2" >DIR2_b && test_cmp DIR2_a DIR2_b &&
101+
ipfs ls "$HASH_DIR1" >DIR1_b && test_cmp DIR1_a DIR1_b
102+
'
103+
104+
test_expect_success "remove dir recursive pin succeeds" '
105+
echo "unpinned $HASH_DIR1" >expected5 &&
106+
ipfs pin rm -r "$HASH_DIR1" >actual5 &&
107+
test_cmp expected5 actual5
108+
'
109+
110+
test_expect_success "none are pinned any more" '
111+
ipfs pin ls -type=recursive >actual6 &&
112+
ipfs pin ls -type=indirect >>actual6 &&
113+
ipfs pin ls -type=direct >>actual6 &&
114+
ipfs pin ls -type=all >>actual6 &&
115+
test_must_fail grep "$HASH_FILE6" actual6 &&
116+
test_must_fail grep "$HASH_FILE5" actual6 &&
117+
test_must_fail grep "$HASH_FILE4" actual6 &&
118+
test_must_fail grep "$HASH_FILE3" actual6 &&
119+
test_must_fail grep "$HASH_FILE2" actual6 &&
120+
test_must_fail grep "$HASH_FILE1" actual6 &&
121+
test_must_fail grep "$HASH_DIR3" actual6 &&
122+
test_must_fail grep "$HASH_DIR4" actual6 &&
123+
test_must_fail grep "$HASH_DIR2" actual6 &&
124+
test_must_fail grep "$HASH_DIR1" actual6
125+
'
126+
127+
test_expect_success "pin some directly and indirectly" '
128+
ipfs pin add "$HASH_DIR1" >actual7 &&
129+
ipfs pin add -r "$HASH_DIR2" >>actual7 &&
130+
ipfs pin add "$HASH_FILE1" >>actual7 &&
131+
echo "pinned $HASH_DIR1 directly" >expected7 &&
132+
echo "pinned $HASH_DIR2 recursively" >>expected7 &&
133+
echo "pinned $HASH_FILE1 directly" >>expected7 &&
134+
test_cmp expected7 actual7
135+
'
136+
137+
test_expect_success "pin lists look good" '
138+
ipfs pin ls -type=recursive >ls_recursive &&
139+
ipfs pin ls -type=indirect >ls_indirect &&
140+
ipfs pin ls -type=direct >ls_direct &&
141+
test_must_fail grep "$HASH_DIR1" ls_indirect &&
142+
grep "$HASH_DIR1" ls_direct &&
143+
test_must_fail grep "$HASH_DIR1" ls_recursive &&
144+
test_must_fail grep "$HASH_DIR2" ls_indirect &&
145+
test_must_fail grep "$HASH_DIR2" ls_direct &&
146+
grep "$HASH_DIR2" ls_recursive &&
147+
test_must_fail grep "$HASH_DIR3" ls_indirect &&
148+
test_must_fail grep "$HASH_DIR3" ls_direct &&
149+
test_must_fail grep "$HASH_DIR3" ls_recursive &&
150+
grep "$HASH_DIR4" ls_indirect &&
151+
test_must_fail grep "$HASH_DIR4" ls_direct &&
152+
test_must_fail grep "$HASH_DIR4" ls_recursive &&
153+
grep "$HASH_FILE1" ls_indirect &&
154+
grep "$HASH_FILE1" ls_direct &&
155+
test_must_fail grep "$HASH_FILE1" ls_recursive &&
156+
grep "$HASH_FILE2" ls_indirect &&
157+
test_must_fail grep "$HASH_FILE2" ls_direct &&
158+
test_must_fail grep "$HASH_FILE2" ls_recursive &&
159+
test_must_fail grep "$HASH_FILE3" ls_indirect &&
160+
test_must_fail grep "$HASH_FILE3" ls_direct &&
161+
test_must_fail grep "$HASH_FILE3" ls_recursive &&
162+
grep "$HASH_FILE4" ls_indirect &&
163+
test_must_fail grep "$HASH_FILE4" ls_direct &&
164+
test_must_fail grep "$HASH_FILE4" ls_recursive &&
165+
test_must_fail grep "$HASH_FILE5" ls_indirect &&
166+
test_must_fail grep "$HASH_FILE5" ls_direct &&
167+
test_must_fail grep "$HASH_FILE5" ls_recursive &&
168+
test_must_fail grep "$HASH_FILE6" ls_indirect &&
169+
grep "$HASH_FILE6" ls_direct &&
170+
grep "$HASH_FILE6" ls_recursive
171+
'
172+
173+
test_expect_success "'ipfs repo gc' succeeds" '
174+
ipfs repo gc >gc_out_actual2 &&
175+
grep "removed $HASH_FILE3" gc_out_actual2 &&
176+
grep "removed $HASH_FILE5" gc_out_actual2 &&
177+
grep "removed $HASH_DIR3" gc_out_actual2
178+
'
179+
180+
test_expect_success "some objects are still there" '
181+
ipfs cat "$HASH_FILE6" >FILE6_b && test_cmp FILE6_a FILE6_b &&
182+
ipfs cat "$HASH_FILE4" >FILE4_b && test_cmp FILE4_a FILE4_b &&
183+
ipfs cat "$HASH_FILE2" >FILE2_b && test_cmp FILE2_a FILE2_b &&
184+
ipfs cat "$HASH_FILE1" >FILE1_b && test_cmp FILE1_a FILE1_b &&
185+
ipfs ls "$HASH_DIR4" >DIR4_b && test_cmp DIR4_a DIR4_b &&
186+
ipfs ls "$HASH_DIR2" >DIR2_b && test_cmp DIR2_a DIR2_b &&
187+
ipfs ls "$HASH_DIR1" >DIR1_b && test_cmp DIR1_a DIR1_b &&
188+
test_must_fail ipfs cat "$HASH_FILE5" &&
189+
test_must_fail ipfs cat "$HASH_FILE3" &&
190+
test_must_fail ipfs ls "$HASH_DIR3"
191+
'
192+
193+
test_expect_success "recursive pin fails without objects" '
194+
ipfs pin rm "$HASH_DIR1" &&
195+
test_must_fail ipfs pin add -r "$HASH_DIR1" 2>err_expected8 &&
196+
grep "context exceeded" err_expected8
197+
'
198+
199+
test_kill_ipfs_daemon
200+
201+
test_done

0 commit comments

Comments
 (0)