@cryptotaxi247 / kubo / commits / 33f699f8d

files api: redo tests

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Jun 26, 2017 at 02:41 UTC 33f699f8de03df8b5ec37f36019b352b43d6f16a
1 file changed +45 -54
test/sharness/t0250-files-api.sh
+45 -54
@@ -10,18 +10,16 @@ test_description="test the unix files api"
10
11 test_init_ipfs
12
13 -# setup files for testing
14 -test_expect_success "can create some files for testing" '
15 - FILE1=$(echo foo | ipfs add -q) &&
16 - FILE2=$(echo bar | ipfs add -q) &&
17 - FILE3=$(echo baz | ipfs add -q) &&
18 - FILE9=$(echo zip | ipfs add -q --raw-leaves) &&
19 - mkdir stuff_test &&
13 +create_files() {
14 + FILE1=$(echo foo | ipfs add "$@" -q) &&
15 + FILE2=$(echo bar | ipfs add "$@" -q) &&
16 + FILE3=$(echo baz | ipfs add "$@" -q) &&
17 + mkdir -p stuff_test &&
18 echo cats > stuff_test/a &&
19 echo dogs > stuff_test/b &&
20 echo giraffes > stuff_test/c &&
23 - DIR1=$(ipfs add -q stuff_test | tail -n1)
24 -'
21 + DIR1=$(ipfs add -r "$@" -q stuff_test | tail -n1)
22 +}
23
24 verify_path_exists() {
25 # simply running ls on a file should be a good 'check'
@@ -91,6 +89,8 @@ test_sharding() {
89 }
90
91 test_files_api() {
92 + ROOT_HASH=$1
93 +
94 test_expect_success "can mkdir in root" '
95 ipfs files mkdir /cats
96 '
@@ -160,6 +160,12 @@ test_files_api() {
160 verify_dir_contents /cats file1
161 '
162
163 + test_expect_success "file has correct hash and size in directory" '
164 + echo "file1 $FILE1 4" > ls_l_expected &&
165 + ipfs files ls -l /cats > ls_l_actual &&
166 + test_cmp ls_l_expected ls_l_actual
167 + '
168 +
169 test_expect_success "can read file" '
170 ipfs files read /cats/file1 > file1out
171 '
@@ -253,42 +259,6 @@ test_files_api() {
259 test_cmp roothash roothashafter
260 '
261
256 - # test raw node
257 -
258 - test_expect_success "can put a raw-node into root" '
259 - ipfs files cp /ipfs/$FILE9 /file9
260 - '
261 -
262 - test_expect_success "file shows up in root" '
263 - verify_dir_contents / file9 cats
264 - '
265 -
266 - test_expect_success "can read file" '
267 - ipfs files read /file9 > file9out
268 - '
269 -
270 - test_expect_success "output looks good" '
271 - echo zip > expected &&
272 - test_cmp expected file9out
273 - '
274 -
275 - test_expect_success "can remove file from root" '
276 - ipfs files rm /file9
277 - '
278 -
279 - test_expect_success "file no longer appears" '
280 - verify_dir_contents / cats
281 - '
282 -
283 - test_expect_success "check root hash" '
284 - ipfs files stat --hash / > roothash
285 - '
286 -
287 - test_expect_success "check root hash was not changed" '
288 - ipfs files stat --hash / > roothashafter &&
289 - test_cmp roothash roothashafter
290 - '
291 -
262 # test read options
263
264 test_expect_success "read from offset works" '
@@ -439,7 +409,7 @@ test_files_api() {
409 test_expect_success "root hash not bubbled up yet" '
410 test -z "$ONLINE" ||
411 (ipfs refs local > refsout &&
442 - test_expect_code 1 grep QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt refsout)
412 + test_expect_code 1 grep $ROOT_HASH refsout)
413 '
414
415 test_expect_success "changes bubbled up to root on inspection" '
@@ -447,7 +417,7 @@ test_files_api() {
417 '
418
419 test_expect_success "root hash looks good" '
450 - export EXP_ROOT_HASH="QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt" &&
420 + export EXP_ROOT_HASH="$ROOT_HASH" &&
421 echo $EXP_ROOT_HASH > root_hash_exp &&
422 test_cmp root_hash_exp root_hash
423 '
@@ -558,26 +528,47 @@ test_files_api() {
528 ipfs files rm -r /foobar &&
529 ipfs files rm -r /adir
530 '
531 +
532 + test_expect_success "root mfs entry is empyt" '
533 + verify_dir_contents /
534 + '
535 +
536 + test_expect_success "repo gc" '
537 + ipfs repo gc
538 + '
539 }
540
541 # test offline and online
564 -test_files_api
542 +test_expect_success "can create some files for testing" '
543 + create_files
544 +'
545 +test_files_api QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt
546
566 -test_expect_success "clean up objects from previous test run" '
567 - ipfs repo gc
547 +test_expect_success "can create some files for testing with raw-leaves" '
548 + create_files --raw-leaves
549 '
550 +test_files_api QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
551
570 -test_launch_ipfs_daemon
552 +test_launch_ipfs_daemon --offline
553
554 ONLINE=1 # set online flag so tests can easily tell
573 -test_files_api
574 -test_kill_ipfs_daemon
555 +test_expect_success "can create some files for testing" '
556 + create_files
557 +'
558 +test_files_api QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt
559 +
560 +test_expect_success "can create some files for testing with raw-leaves" '
561 + create_files --raw-leaves
562 +'
563 +test_files_api QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
564 +
565 +test_kill_ipfs_daemon --offline
566
567 test_expect_success "enable sharding in config" '
568 ipfs config --json Experimental.ShardingEnabled true
569 '
570
580 -test_launch_ipfs_daemon
571 +test_launch_ipfs_daemon --offline
572 test_sharding
573 test_kill_ipfs_daemon
574