@cryptotaxi247 / kubo / commits / 220b9d22a

Move test add cat offline into t0040

License: MIT Signed-off-by: rht <rhtbot@gmail.com>

rht committed Oct 3, 2015 at 08:42 UTC 220b9d22ae6b89e68a111a125caf956ec2b3c13c
2 files changed +155 -187
test/sharness/t0040-add-and-cat.sh
+155 -112
@@ -12,6 +12,146 @@ client_err() {
12 printf "$@\n\nUse 'ipfs add --help' for information about this command\n"
13 }
14
15 +test_add_cat_file() {
16 + test_expect_success "ipfs add succeeds" '
17 + echo "Hello Worlds!" >mountdir/hello.txt &&
18 + ipfs add mountdir/hello.txt >actual
19 + '
20 +
21 + test_expect_success "ipfs add output looks good" '
22 + HASH="QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH" &&
23 + echo "added $HASH hello.txt" >expected &&
24 + test_cmp expected actual
25 + '
26 +
27 + test_expect_success "ipfs add --only-hash succeeds" '
28 + ipfs add --only-hash mountdir/hello.txt > oh_actual
29 + '
30 +
31 + test_expect_success "ipfs add --only-hash output looks good" '
32 + test_cmp expected oh_actual
33 + '
34 +
35 + test_expect_success "ipfs cat succeeds" '
36 + ipfs cat "$HASH" >actual
37 + '
38 +
39 + test_expect_success "ipfs cat output looks good" '
40 + echo "Hello Worlds!" >expected &&
41 + test_cmp expected actual
42 + '
43 +
44 + test_expect_success "ipfs cat /ipfs/file succeeds" '
45 + ipfs cat /ipfs/$HASH >actual
46 + '
47 +
48 + test_expect_success "output looks good" '
49 + test_cmp expected actual
50 + '
51 +}
52 +
53 +test_add_cat_5MB() {
54 + test_expect_success "generate 5MB file using go-random" '
55 + random 5242880 41 >mountdir/bigfile
56 + '
57 +
58 + test_expect_success "sha1 of the file looks ok" '
59 + echo "11145620fb92eb5a49c9986b5c6844efda37e471660e" >sha1_expected &&
60 + multihash -a=sha1 -e=hex mountdir/bigfile >sha1_actual &&
61 + test_cmp sha1_expected sha1_actual
62 + '
63 +
64 + test_expect_success "'ipfs add bigfile' succeeds" '
65 + ipfs add mountdir/bigfile >actual
66 + '
67 +
68 + test_expect_success "'ipfs add bigfile' output looks good" '
69 + HASH="QmSr7FqYkxYWGoSfy8ZiaMWQ5vosb18DQGCzjwEQnVHkTb" &&
70 + echo "added $HASH bigfile" >expected &&
71 + test_cmp expected actual
72 + '
73 + test_expect_success "'ipfs cat' succeeds" '
74 + ipfs cat "$HASH" >actual
75 + '
76 +
77 + test_expect_success "'ipfs cat' output looks good" '
78 + test_cmp mountdir/bigfile actual
79 + '
80 +
81 + test_expect_success FUSE "cat ipfs/bigfile succeeds" '
82 + cat "ipfs/$HASH" >actual
83 + '
84 +
85 + test_expect_success FUSE "cat ipfs/bigfile looks good" '
86 + test_cmp mountdir/bigfile actual
87 + '
88 +}
89 +
90 +test_add_cat_expensive() {
91 + test_expect_success EXPENSIVE "generate 100MB file using go-random" '
92 + random 104857600 42 >mountdir/bigfile
93 + '
94 +
95 + test_expect_success EXPENSIVE "sha1 of the file looks ok" '
96 + echo "1114885b197b01e0f7ff584458dc236cb9477d2e736d" >sha1_expected &&
97 + multihash -a=sha1 -e=hex mountdir/bigfile >sha1_actual &&
98 + test_cmp sha1_expected sha1_actual
99 + '
100 +
101 + test_expect_success EXPENSIVE "ipfs add bigfile succeeds" '
102 + ipfs add mountdir/bigfile >actual
103 + '
104 +
105 + test_expect_success EXPENSIVE "ipfs add bigfile output looks good" '
106 + HASH="QmU9SWAPPmNEKZB8umYMmjYvN7VyHqABNvdA6GUi4MMEz3" &&
107 + echo "added $HASH bigfile" >expected &&
108 + test_cmp expected actual
109 + '
110 +
111 + test_expect_success EXPENSIVE "ipfs cat succeeds" '
112 + ipfs cat "$HASH" | multihash -a=sha1 -e=hex >sha1_actual
113 + '
114 +
115 + test_expect_success EXPENSIVE "ipfs cat output looks good" '
116 + ipfs cat "$HASH" >actual &&
117 + test_cmp mountdir/bigfile actual
118 + '
119 +
120 + test_expect_success EXPENSIVE "ipfs cat output hashed looks good" '
121 + echo "1114885b197b01e0f7ff584458dc236cb9477d2e736d" >sha1_expected &&
122 + test_cmp sha1_expected sha1_actual
123 + '
124 +
125 + test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile succeeds" '
126 + cat "ipfs/$HASH" | multihash -a=sha1 -e=hex >sha1_actual
127 + '
128 +
129 + test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile looks good" '
130 + test_cmp sha1_expected sha1_actual
131 + '
132 +}
133 +
134 +test_add_named_pipe() {
135 + err_prefix=$1
136 + test_expect_success "useful error message when adding a named pipe" '
137 + mkfifo named-pipe &&
138 + test_expect_code 1 ipfs add named-pipe 2>actual &&
139 + client_err "Error: Unrecognized file type for named-pipe: $(generic_stat named-pipe)" >expected &&
140 + rm named-pipe &&
141 + test_cmp expected actual
142 + '
143 +
144 + test_expect_success "useful error message when recursively adding a named pipe" '
145 + mkdir -p named-pipe-dir &&
146 + mkfifo named-pipe-dir/named-pipe &&
147 + test_expect_code 1 ipfs add -r named-pipe-dir 2>actual &&
148 + printf "Error:$err_prefix Unrecognized file type for named-pipe-dir/named-pipe: $(generic_stat named-pipe-dir/named-pipe)\n" >expected &&
149 + rm named-pipe-dir/named-pipe &&
150 + rmdir named-pipe-dir &&
151 + test_cmp expected actual
152 + '
153 +}
154 +
155 test_launch_ipfs_daemon_and_mount
156
157 test_expect_success "'ipfs add --help' succeeds" '
@@ -32,33 +172,7 @@ test_expect_success "'ipfs cat --help' output looks good" '
172 test_fsh cat actual
173 '
174
35 -test_expect_success "ipfs add succeeds" '
36 - echo "Hello Worlds!" >mountdir/hello.txt &&
37 - ipfs add mountdir/hello.txt >actual
38 -'
39 -
40 -test_expect_success "ipfs add output looks good" '
41 - HASH="QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH" &&
42 - echo "added $HASH hello.txt" >expected &&
43 - test_cmp expected actual
44 -'
45 -
46 -test_expect_success "ipfs add --only-hash succeeds" '
47 - ipfs add --only-hash mountdir/hello.txt > oh_actual
48 -'
49 -
50 -test_expect_success "ipfs add --only-hash output looks good" '
51 - ipfs add --only-hash mountdir/hello.txt > oh_actual
52 -'
53 -
54 -test_expect_success "ipfs cat succeeds" '
55 - ipfs cat "$HASH" >actual
56 -'
57 -
58 -test_expect_success "ipfs cat output looks good" '
59 - echo "Hello Worlds!" >expected &&
60 - test_cmp expected actual
61 -'
175 +test_add_cat_file
176
177 test_expect_success "ipfs cat succeeds with stdin opened (issue #1141)" '
178 cat mountdir/hello.txt | while read line; do ipfs cat "$HASH" >actual || exit; done
@@ -186,101 +300,30 @@ test_expect_success "ipfs cat output looks good" '
300 '
301
302 test_expect_success "go-random is installed" '
189 - type random
190 -'
191 -
192 -test_expect_success "generate 5MB file using go-random" '
193 - random 5242880 41 >mountdir/bigfile
194 -'
195 -
196 -test_expect_success "sha1 of the file looks ok" '
197 - echo "11145620fb92eb5a49c9986b5c6844efda37e471660e" >sha1_expected &&
198 - multihash -a=sha1 -e=hex mountdir/bigfile >sha1_actual &&
199 - test_cmp sha1_expected sha1_actual
200 -'
201 -
202 -test_expect_success "'ipfs add bigfile' succeeds" '
203 - ipfs add mountdir/bigfile >actual
204 -'
303 + type random
304 + '
305
206 -test_expect_success "'ipfs add bigfile' output looks good" '
207 - HASH="QmSr7FqYkxYWGoSfy8ZiaMWQ5vosb18DQGCzjwEQnVHkTb" &&
208 - echo "added $HASH bigfile" >expected &&
209 - test_cmp expected actual
210 -'
211 -test_expect_success "'ipfs cat' succeeds" '
212 - ipfs cat "$HASH" >actual
213 -'
214 -
215 -test_expect_success "'ipfs cat' output looks good" '
216 - test_cmp mountdir/bigfile actual
217 -'
218 -
219 -test_expect_success FUSE "cat ipfs/bigfile succeeds" '
220 - cat "ipfs/$HASH" >actual
221 -'
222 -
223 -test_expect_success FUSE "cat ipfs/bigfile looks good" '
224 - test_cmp mountdir/bigfile actual
225 -'
306 +test_add_cat_5MB
307
227 -test_expect_success EXPENSIVE "generate 100MB file using go-random" '
228 - random 104857600 42 >mountdir/bigfile
229 -'
230 -
231 -test_expect_success EXPENSIVE "sha1 of the file looks ok" '
232 - echo "1114885b197b01e0f7ff584458dc236cb9477d2e736d" >sha1_expected &&
233 - multihash -a=sha1 -e=hex mountdir/bigfile >sha1_actual &&
234 - test_cmp sha1_expected sha1_actual
235 -'
308 +test_add_cat_expensive
309
237 -test_expect_success EXPENSIVE "ipfs add bigfile succeeds" '
238 - ipfs add mountdir/bigfile >actual
239 -'
310 +test_add_named_pipe " Post http://127.0.0.1:$PORT_API/api/v0/add?encoding=json&progress=true&r=true&stream-channels=true:"
311
241 -test_expect_success EXPENSIVE "ipfs add bigfile output looks good" '
242 - HASH="QmU9SWAPPmNEKZB8umYMmjYvN7VyHqABNvdA6GUi4MMEz3" &&
243 - echo "added $HASH bigfile" >expected &&
244 - test_cmp expected actual
245 -'
246 -
247 -test_expect_success EXPENSIVE "ipfs cat succeeds" '
248 - ipfs cat "$HASH" | multihash -a=sha1 -e=hex >sha1_actual
249 -'
250 -
251 -test_expect_success EXPENSIVE "ipfs cat output looks good" '
252 - ipfs cat "$HASH" >actual &&
253 - test_cmp mountdir/bigfile actual
254 -'
255 -
256 -test_expect_success EXPENSIVE "ipfs cat output hashed looks good" '
257 - echo "1114885b197b01e0f7ff584458dc236cb9477d2e736d" >sha1_expected &&
258 - test_cmp sha1_expected sha1_actual
259 -'
312 +test_kill_ipfs_daemon
313
261 -test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile succeeds" '
262 - cat "ipfs/$HASH" | multihash -a=sha1 -e=hex >sha1_actual
263 -'
314 +# should work offline
315
265 -test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile looks good" '
266 - test_cmp sha1_expected sha1_actual
267 -'
316 +test_add_cat_file
317
269 -test_expect_success "useful error message when adding a named pipe" '
270 - mkfifo named-pipe &&
271 - test_expect_code 1 ipfs add named-pipe 2>actual &&
272 - client_err "Error: Unrecognized file type for named-pipe: $(generic_stat named-pipe)" >expected &&
273 - test_cmp expected actual
318 +test_expect_success "ipfs add --only-hash succeeds" '
319 + echo "unknown content for only-hash" | ipfs add --only-hash -q > oh_hash
320 '
321
276 -test_expect_success "useful error message when recursively adding a named pipe" '
277 - mkdir named-pipe-dir &&
278 - mkfifo named-pipe-dir/named-pipe &&
279 - test_expect_code 1 ipfs add -r named-pipe-dir 2>actual &&
280 - printf "Error: Post http://127.0.0.1:$PORT_API/api/v0/add?encoding=json&progress=true&r=true&stream-channels=true: Unrecognized file type for named-pipe-dir/named-pipe: $(generic_stat named-pipe-dir/named-pipe)\n" >expected &&
281 - test_cmp expected actual
322 +#TODO: this doesn't work when online hence separated out from test_add_cat_file
323 +test_expect_success "ipfs cat file fails" '
324 + test_must_fail ipfs cat $(cat oh_hash)
325 '
326
284 -test_kill_ipfs_daemon
327 +test_add_named_pipe ""
328
329 test_done
test/sharness/t0041-add-cat-offline.sh deleted
-75
@@ -1,75 +0,0 @@
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 add and cat commands"
8 -
9 -. lib/test-lib.sh
10 -
11 -client_err() {
12 - printf "$@\n\nUse 'ipfs add --help' for information about this command\n"
13 -}
14 -
15 -test_init_ipfs
16 -
17 -test_expect_success "ipfs add file succeeds" '
18 - echo "some content" > afile &&
19 - HASH=$(ipfs add -q afile)
20 -'
21 -
22 -test_expect_success "ipfs add output looks good" '
23 - echo Qmb1EXrDyKhNWfvLPYK4do3M9nU7BuLAcbqBir6aUrDsRY > expected &&
24 - echo $HASH > actual &&
25 - test_cmp expected actual
26 -'
27 -
28 -test_expect_success "ipfs add --only-hash succeeds" '
29 - ipfs add -q --only-hash afile > ho_output
30 -'
31 -
32 -test_expect_success "ipfs add --only-hash output looks good" '
33 - test_cmp expected ho_output
34 -'
35 -
36 -test_expect_success "ipfs cat file suceeds" '
37 - ipfs cat $HASH > out_1
38 -'
39 -
40 -test_expect_success "output looks good" '
41 - test_cmp afile out_1
42 -'
43 -
44 -test_expect_success "ipfs cat /ipfs/file succeeds" '
45 - ipfs cat /ipfs/$HASH > out_2
46 -'
47 -
48 -test_expect_success "output looks good" '
49 - test_cmp afile out_2
50 -'
51 -
52 -test_expect_success "ipfs add --only-hash succeeds" '
53 - echo "unknown content for only-hash" | ipfs add --only-hash -q > oh_hash
54 -'
55 -
56 -test_expect_success "ipfs cat file fails" '
57 - test_must_fail ipfs cat $(cat oh_hash)
58 -'
59 -
60 -test_expect_success "useful error message when adding a named pipe" '
61 - mkfifo named-pipe &&
62 - test_expect_code 1 ipfs add named-pipe 2>actual &&
63 - client_err "Error: Unrecognized file type for named-pipe: $(generic_stat named-pipe)" >expected &&
64 - test_cmp expected actual
65 -'
66 -
67 -test_expect_success "useful error message when recursively adding a named pipe" '
68 - mkdir named-pipe-dir &&
69 - mkfifo named-pipe-dir/named-pipe &&
70 - test_expect_code 1 ipfs add -r named-pipe-dir 2>actual &&
71 - printf "Error: Unrecognized file type for named-pipe-dir/named-pipe: $(generic_stat named-pipe-dir/named-pipe)\n" >expected &&
72 - test_cmp expected actual
73 -'
74 -
75 -test_done