Enhance sharness tests.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Kevin Atkinson committed
Aug 16, 2017 at 17:24 UTC
47c198ceb826f7b49b0681880b8e3554a1f6ee0c
1 file changed
+86
-15
test/sharness/t0250-files-api.sh
+86
-15
@@ -46,11 +46,15 @@ verify_dir_contents() {
46
}
47
48
test_sharding() {
49
- test_expect_success "make a directory" '
50
- ipfs files mkdir /foo
49
+ local EXTRA ARGS
50
+ EXTRA=$1
51
+ ARGS=$2 # only applied to the initial directory
52
+
53
+ test_expect_success "make a directory $EXTRA" '
54
+ ipfs files $ARGS mkdir /foo
55
'
56
53
- test_expect_success "can make 100 files in a directory" '
57
+ test_expect_success "can make 100 files in a directory $EXTRA" '
58
printf "" > list_exp_raw
59
for i in `seq 100`
60
do
@@ -59,33 +63,37 @@ test_sharding() {
63
done
64
'
65
62
- test_expect_success "listing works" '
66
+ test_expect_success "listing works $EXTRA" '
67
ipfs files ls /foo |sort > list_out &&
68
sort list_exp_raw > list_exp &&
69
test_cmp list_exp list_out
70
'
71
68
- test_expect_success "can read a file from sharded directory" '
72
+ test_expect_success "can read a file from sharded directory $EXTRA" '
73
ipfs files read /foo/file65 > file_out &&
74
echo "65" > file_exp &&
75
test_cmp file_out file_exp
76
'
77
74
- test_expect_success "can pin a file from sharded directory" '
78
+ test_expect_success "can pin a file from sharded directory $EXTRA" '
79
ipfs files stat --hash /foo/file42 > pin_file_hash &&
80
ipfs pin add < pin_file_hash > pin_hash
81
'
82
79
- test_expect_success "can unpin a file from sharded directory" '
83
+ test_expect_success "can unpin a file from sharded directory $EXTRA" '
84
read -r _ HASH _ < pin_hash &&
85
ipfs pin rm $HASH
86
'
87
84
- test_expect_success "output object was really sharded" '
88
+ test_expect_success "output object was really sharded and has correct hash $EXTRA" '
89
ipfs files stat --hash /foo > expected_foo_hash &&
86
- echo QmPkwLJTYZRGPJ8Lazr9qPdrLmswPtUjaDbEpmR9jEh1se > actual_foo_hash &&
90
+ echo $SHARD_HASH > actual_foo_hash &&
91
test_cmp expected_foo_hash actual_foo_hash
92
'
93
+
94
+ test_expect_success "clean up $EXTRA" '
95
+ ipfs files rm -r /foo
96
+ '
97
}
98
99
test_files_api() {
@@ -429,6 +437,13 @@ test_files_api() {
437
test_cmp root_hash_exp root_hash
438
'
439
440
+ test_expect_success "/cats hash looks good $EXTRA" '
441
+ export EXP_CATS_HASH="$CATS_HASH" &&
442
+ echo $EXP_CATS_HASH > cats_hash_exp &&
443
+ ipfs files stat --hash /cats > cats_hash
444
+ test_cmp cats_hash_exp cats_hash
445
+ '
446
+
447
test_expect_success "flush root succeeds $EXTRA" '
448
ipfs files $ARGS flush /
449
'
@@ -466,6 +481,12 @@ test_files_api() {
481
test_cmp file_out file_exp
482
'
483
484
+ test_expect_success "file hash correct $EXTRA" '
485
+ echo $TRUNC_HASH > filehash_expected &&
486
+ ipfs files $ARGS stat --hash /cats > filehash &&
487
+ test_cmp filehash_expected filehash
488
+ '
489
+
490
test_expect_success "cleanup $EXTRA" '
491
ipfs files $ARGS rm /cats
492
'
@@ -555,21 +576,65 @@ tests_for_files_api() {
576
create_files
577
'
578
ROOT_HASH=QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt
579
+ CATS_HASH=Qma88m8ErTGkZHbBWGqy1C7VmEmX8wwNDWNpGyCaNmEgwC
580
FILE_HASH=QmQdQt9qooenjeaNhiKHF3hBvmNteB4MQBtgu3jxgf9c7i
581
+ TRUNC_HASH=QmdaQZbLwK5ykweGdCVovNnvBom7QhikovDUVqTPHQG4L8
582
test_files_api "($EXTRA)"
583
584
test_expect_success "can create some files for testing with raw-leaves ($extra)" '
585
create_files --raw-leaves
586
'
564
- ROOT_HASH=QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
565
- test_files_api "($EXTRA, partial raw-leaves)"
587
567
- test_expect_success "can create some files for testing with raw-leaves ($extra)" '
568
- create_files --raw-leaves
569
- '
588
+ if [ "$EXTRA" = "offline" ]; then
589
+ ROOT_HASH=QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
590
+ CATS_HASH=QmPhPkmtUGGi8ySPHoPu1qbfryLJKKq1GYxpgLyyCruvGe
591
+ test_files_api "($EXTRA, partial raw-leaves)"
592
+ fi
593
+
594
ROOT_HASH=QmW3dMSU6VNd1mEdpk9S3ZYRuR1YwwoXjGaZhkyK6ru9YU
595
+ CATS_HASH=QmPqWDEg7NoWRX8Y4vvYjZtmdg5umbfsTQ9zwNr12JoLmt
596
FILE_HASH=QmRCgHeoKxCqK2Es6M6nPUDVWz19yNQPnsXGsXeuTkSKpN
597
+ TRUNC_HASH=QmRFJEKWF5A5FyFYZgNhusLw2UziW9zBKYr4huyHjzcB6o
598
test_files_api "($EXTRA, raw-leaves)" --raw-leaves
599
+
600
+ ROOT_HASH=QmageRWxC7wWjPv5p36NeAgBAiFdBHaNfxAehBSwzNech2
601
+ CATS_HASH=zdj7WkEzPLNAr5TYJSQC8CFcBjLvWFfGdx6kaBrJXnBguwWeX
602
+ FILE_HASH=zdj7WYHvf5sBRgSBjYnq64QFr449CCbgupXfBvoYL3aHC1DzJ
603
+ TRUNC_HASH=zdj7WYLYbka6Ydg8gZUJRLKnFBVehCADhQKBsFbNiMxZSB5Gj
604
+ if [ "$EXTRA" = "offline" ]; then
605
+ test_files_api "($EXTRA, cidv1)" --cid-version=1
606
+ fi
607
+
608
+ test_expect_success "can update root hash to cidv1" '
609
+ ipfs files --cid-version=1 update / &&
610
+ echo zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi > hash_expect &&
611
+ ipfs files stat --hash / > hash_actual &&
612
+ test_cmp hash_expect hash_actual
613
+ '
614
+
615
+ ROOT_HASH=zdj7Whmtnx23bR7c7E1Yn3zWYWjnvT4tpzWYGaBMyqcopDWrx
616
+ test_files_api "($EXTRA, cidv1 root)"
617
+
618
+ if [ "$EXTRA" = "offline" ]; then
619
+ test_expect_success "can update root hash to blake2b-256" '
620
+ ipfs files --hash-fun=blake2b-256 update / &&
621
+ echo zDMZof1kvswQMT8txrmnb3JGBuna6qXCTry6hSifrkZEd6VmHbBm > hash_expect &&
622
+ ipfs files stat --hash / > hash_actual &&
623
+ test_cmp hash_expect hash_actual
624
+ '
625
+ ROOT_HASH=zDMZof1kxEsAwSgCZsGQRVcHCMtHLjkUQoiZUbZ87erpPQJGUeW8
626
+ CATS_HASH=zDMZof1kuAhr3zBkxq48V7o9HJZCTVyu1Wd9wnZtVcPJLW8xnGft
627
+ FILE_HASH=zDMZof1kxbB9CvxgRioBzESbGnZUxtSCsZ18H1EUkxDdWt1DYEkK
628
+ TRUNC_HASH=zDMZof1kxXqKdVsVo231qVdN3hCTF5a34UuQZpzmm5K7CbRJ4u2S
629
+ test_files_api "($EXTRA, blake2b-256 root)"
630
+ fi
631
+
632
+ test_expect_success "can update root hash back to cidv0" '
633
+ ipfs files --cid-version=0 update / &&
634
+ echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn > hash_expect &&
635
+ ipfs files stat --hash / > hash_actual &&
636
+ test_cmp hash_expect hash_actual
637
+ '
638
}
639
640
tests_for_files_api "online"
@@ -587,7 +652,13 @@ test_expect_success "enable sharding in config" '
652
'
653
654
test_launch_ipfs_daemon --offline
590
-test_sharding
655
+
656
+SHARD_HASH=QmPkwLJTYZRGPJ8Lazr9qPdrLmswPtUjaDbEpmR9jEh1se
657
+test_sharding "(cidv0)"
658
+
659
+SHARD_HASH=zdj7WZXr6vG2Ne7ZLHGEKrGyF3pHBfAViEnmH9CoyvjrFQM8E
660
+test_sharding "(cidv1 root)" "--cid-version=1"
661
+
662
test_kill_ipfs_daemon
663
664
test_done