@cryptotaxi247 / kubo / commits / 83e88a8e2

test/sharness: improve t0080

The following changes are made to make t0080 cleaner, safer and more canonical: - remove useless stuff, - don't use a pipe after ipfs commands, - use test_must_fail before ipfs commands instead of ! License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Christian Couder committed Feb 2, 2015 at 01:04 UTC 83e88a8e2b5b2f38fe558c68c1556518224aab62
1 file changed +34 -25
test/sharness/t0080-repo.sh
+34 -25
@@ -13,12 +13,12 @@ test_launch_ipfs_daemon
13
14 test_expect_success "'ipfs add afile' succeeds" '
15 echo "some text" >afile &&
16 - HASH=`ipfs add -q afile` &&
17 - printf "$HASH" >hashfile
16 + HASH=`ipfs add -q afile`
17 '
18
19 test_expect_success "added file was pinned" '
21 - ipfs pin ls -type=recursive | grep "$HASH"
20 + ipfs pin ls -type=recursive >actual &&
21 + grep "$HASH" actual
22 '
23
24 test_expect_success "'ipfs repo gc' succeeds" '
@@ -26,7 +26,7 @@ test_expect_success "'ipfs repo gc' succeeds" '
26 '
27
28 test_expect_success "'ipfs repo gc' looks good (empty)" '
29 - printf "" >empty &&
29 + true >empty &&
30 test_cmp empty gc_out_actual
31 '
32
@@ -36,8 +36,11 @@ test_expect_success "'ipfs repo gc' doesnt remove file" '
36 '
37
38 test_expect_success "'ipfs pin rm' succeeds" '
39 + ipfs pin rm -r "$HASH" >actual1
40 +'
41 +
42 +test_expect_success "'ipfs pin rm' output looks good" '
43 echo "unpinned $HASH" >expected1 &&
40 - ipfs pin rm -r "$HASH" >actual1 &&
44 test_cmp expected1 actual1
45 '
46
@@ -45,9 +48,10 @@ test_expect_success "file no longer pinned" '
48 # we expect the welcome files to show up here
49 echo "$HASH_WELCOME_DOCS" >expected2 &&
50 ipfs refs -r "$HASH_WELCOME_DOCS" >>expected2 &&
48 - cat expected2 | sort >expected_sorted2 &&
49 - ipfs pin ls -type=recursive | sort >actual2 &&
50 - test_cmp expected_sorted2 actual2
51 + sort expected2 >expected_sorted2 &&
52 + ipfs pin ls -type=recursive >actual2 &&
53 + sort actual2 >actual_sorted2 &&
54 + test_cmp expected_sorted2 actual_sorted2
55 '
56
57 test_expect_success "recursively pin afile" '
@@ -56,13 +60,13 @@ test_expect_success "recursively pin afile" '
60
61 test_expect_success "pinning directly should fail now" '
62 echo "Error: pin: $HASH already pinned recursively" >expected3 &&
59 - !(ipfs pin add "$HASH" 2>actual3) &&
63 + test_must_fail ipfs pin add "$HASH" 2>actual3 &&
64 test_cmp expected3 actual3
65 '
66
67 test_expect_success "'ipfs pin rm <hash>' should fail" '
68 echo "Error: $HASH is pinned recursively" >expected4 &&
65 - !(ipfs pin rm "$HASH" 2>actual4) &&
69 + test_must_fail ipfs pin rm "$HASH" 2>actual4 &&
70 test_cmp expected4 actual4
71 '
72
@@ -89,9 +93,10 @@ test_expect_success "'ipfs refs local' no longer shows file" '
93 echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >expected8 &&
94 echo "$HASH_WELCOME_DOCS" >>expected8 &&
95 ipfs refs -r "$HASH_WELCOME_DOCS" >>expected8 &&
92 - cat expected8 | sort >expected_sorted8 &&
93 - ipfs refs local | sort >actual8 &&
94 - test_cmp expected_sorted8 actual8
96 + sort expected8 >expected_sorted8 &&
97 + ipfs refs local >actual8 &&
98 + sort actual8 >actual_sorted8 &&
99 + test_cmp expected_sorted8 actual_sorted8
100 '
101
102 test_expect_success "adding multiblock random file succeeds" '
@@ -102,9 +107,10 @@ test_expect_success "adding multiblock random file succeeds" '
107 test_expect_success "'ipfs pin ls -type=indirect' is correct" '
108 ipfs refs "$MBLOCKHASH" >refsout &&
109 ipfs refs -r "$HASH_WELCOME_DOCS" >>refsout &&
105 - cat refsout | sort >refsout_sorted &&
106 - ipfs pin ls -type=indirect | sort >indirectpins &&
107 - test_cmp refsout_sorted indirectpins
110 + sort refsout >refsout_sorted &&
111 + ipfs pin ls -type=indirect >indirectpins &&
112 + sort indirectpins >indirectpins_sorted &&
113 + test_cmp refsout_sorted indirectpins_sorted
114 '
115
116 test_expect_success "pin something directly" '
@@ -122,27 +128,30 @@ test_expect_success "pin something directly" '
128 test_expect_success "'ipfs pin ls -type=direct' is correct" '
129 echo "$DIRECTPIN" >directpinexpected &&
130 echo QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn >>directpinexpected &&
125 - cat directpinexpected | sort >dp_exp_sorted &&
126 - ipfs pin ls -type=direct | sort >directpinout &&
127 - test_cmp dp_exp_sorted directpinout
131 + sort directpinexpected >dp_exp_sorted &&
132 + ipfs pin ls -type=direct >directpinout &&
133 + sort directpinout >dp_out_sorted &&
134 + test_cmp dp_exp_sorted dp_out_sorted
135 '
136
137 test_expect_success "'ipfs pin ls -type=recursive' is correct" '
138 echo "$MBLOCKHASH" >rp_expected &&
139 echo "$HASH_WELCOME_DOCS" >>rp_expected &&
140 ipfs refs -r "$HASH_WELCOME_DOCS" >>rp_expected &&
134 - cat rp_expected | sort >rp_exp_sorted &&
135 - ipfs pin ls -type=recursive | sort >rp_actual &&
136 - test_cmp rp_exp_sorted rp_actual
141 + sort rp_expected >rp_exp_sorted &&
142 + ipfs pin ls -type=recursive >rp_actual &&
143 + sort rp_actual >rp_act_sorted &&
144 + test_cmp rp_exp_sorted rp_act_sorted
145 '
146
147 test_expect_success "'ipfs pin ls -type=all' is correct" '
148 cat directpinout >allpins &&
149 cat rp_actual >>allpins &&
150 cat indirectpins >>allpins &&
143 - cat allpins | sort >allpins_sorted &&
144 - ipfs pin ls -type=all | sort >actual_allpins &&
145 - test_cmp allpins_sorted actual_allpins
151 + sort allpins >allpins_sorted &&
152 + ipfs pin ls -type=all >actual_allpins &&
153 + sort actual_allpins >actual_allpins_sorted &&
154 + test_cmp allpins_sorted actual_allpins_sorted
155 '
156
157 test_kill_ipfs_daemon