use --repo-dir in sharness/t0020-init.sh
Lucas Molas committed
Mar 24, 2022 at 21:43 UTC
447462b80100c29822058503a9c72b900e5265cb
1 file changed
+53
-53
test/sharness/t0020-init.sh
+53
-53
@@ -8,23 +8,23 @@ test_description="Test init command"
8
9
. lib/test-lib.sh
10
11
-# test that ipfs fails to init if IPFS_PATH isn't writeable
11
+# test that ipfs fails to init with BAD_IPFS_DIR that isn't writeable
12
test_expect_success "create dir and change perms succeeds" '
13
- export IPFS_PATH="$(pwd)/.badipfs" &&
14
- mkdir "$IPFS_PATH" &&
15
- chmod 000 "$IPFS_PATH"
13
+ export BAD_IPFS_DIR="$(pwd)/.badipfs" &&
14
+ mkdir "$BAD_IPFS_DIR" &&
15
+ chmod 000 "$BAD_IPFS_DIR"
16
'
17
18
test_expect_success "ipfs init fails" '
19
- test_must_fail ipfs init 2> init_fail_out
19
+ test_must_fail ipfs init --repo-dir "$BAD_IPFS_DIR" 2> init_fail_out
20
'
21
22
# Under Windows/Cygwin the error message is different,
23
# so we use the STD_ERR_MSG prereq.
24
if test_have_prereq STD_ERR_MSG; then
25
- init_err_msg="Error: error loading plugins: open $IPFS_PATH/config: permission denied"
25
+ init_err_msg="Error: error loading plugins: open $BAD_IPFS_DIR/config: permission denied"
26
else
27
- init_err_msg="Error: error loading plugins: open $IPFS_PATH/config: The system cannot find the path specified."
27
+ init_err_msg="Error: error loading plugins: open $BAD_IPFS_DIR/config: The system cannot find the path specified."
28
fi
29
30
test_expect_success "ipfs init output looks good" '
@@ -33,19 +33,19 @@ test_expect_success "ipfs init output looks good" '
33
'
34
35
test_expect_success "cleanup dir with bad perms" '
36
- chmod 775 "$IPFS_PATH" &&
37
- rmdir "$IPFS_PATH"
36
+ chmod 775 "$BAD_IPFS_DIR" &&
37
+ rmdir "$BAD_IPFS_DIR"
38
'
39
40
# test no repo error message
41
# this applies to `ipfs add sth`, `ipfs refs <hash>`
42
test_expect_success "ipfs cat fails" '
43
- export IPFS_PATH="$(pwd)/.ipfs" &&
44
- test_must_fail ipfs cat Qmaa4Rw81a3a1VEx4LxB7HADUAXvZFhCoRdBzsMZyZmqHD 2> cat_fail_out
43
+ export IPFS_DIR="$(pwd)/.ipfs" &&
44
+ test_must_fail ipfs cat --repo-dir "$IPFS_DIR" Qmaa4Rw81a3a1VEx4LxB7HADUAXvZFhCoRdBzsMZyZmqHD 2> cat_fail_out
45
'
46
47
test_expect_success "ipfs cat no repo message looks good" '
48
- echo "Error: no IPFS repo found in $IPFS_PATH." > cat_fail_exp &&
48
+ echo "Error: no IPFS repo found in $IPFS_DIR." > cat_fail_exp &&
49
echo "please run: '"'"'ipfs init'"'"'" >> cat_fail_exp &&
50
test_path_cmp cat_fail_exp cat_fail_out
51
'
@@ -56,39 +56,39 @@ test_ipfs_init_flags() {
56
57
# test that init succeeds
58
test_expect_success "ipfs init succeeds" '
59
- export IPFS_PATH="$(pwd)/.ipfs" &&
60
- echo "IPFS_PATH: \"$IPFS_PATH\"" &&
59
+ export IPFS_DIR="$(pwd)/.ipfs" &&
60
+ echo "IPFS_DIR: \"$IPFS_DIR\"" &&
61
RSA_BITS="2048" &&
62
case $TEST_ALG in
63
"rsa")
64
- ipfs init --algorithm=rsa --bits="$RSA_BITS" >actual_init || test_fsh cat actual_init
64
+ ipfs init --repo-dir "$IPFS_DIR" --algorithm=rsa --bits="$RSA_BITS" >actual_init || test_fsh cat actual_init
65
;;
66
"ed25519")
67
- ipfs init --algorithm=ed25519 >actual_init || test_fsh cat actual_init
67
+ ipfs init --repo-dir "$IPFS_DIR" --algorithm=ed25519 >actual_init || test_fsh cat actual_init
68
;;
69
*)
70
- ipfs init --algorithm=rsa --bits="$RSA_BITS" >actual_init || test_fsh cat actual_init
70
+ ipfs init --repo-dir "$IPFS_DIR" --algorithm=rsa --bits="$RSA_BITS" >actual_init || test_fsh cat actual_init
71
;;
72
esac
73
'
74
75
test_expect_success ".ipfs/ has been created" '
76
- test -d ".ipfs" &&
77
- test -f ".ipfs/config" &&
78
- test -d ".ipfs/datastore" &&
79
- test -d ".ipfs/blocks" &&
76
+ test -d "$IPFS_DIR" &&
77
+ test -f "$IPFS_DIR/config" &&
78
+ test -d "$IPFS_DIR/datastore" &&
79
+ test -d "$IPFS_DIR/blocks" &&
80
test ! -f ._check_writeable ||
81
- test_fsh ls -al .ipfs
81
+ test_fsh ls -al $IPFS_DIR
82
'
83
84
test_expect_success "ipfs config succeeds" '
85
echo /ipfs >expected_config &&
86
- ipfs config Mounts.IPFS >actual_config &&
86
+ ipfs config --repo-dir "$IPFS_DIR" Mounts.IPFS >actual_config &&
87
test_cmp expected_config actual_config
88
'
89
90
test_expect_success "ipfs peer id looks good" '
91
- PEERID=$(ipfs config Identity.PeerID) &&
91
+ PEERID=$(ipfs config --repo-dir "$IPFS_DIR" Identity.PeerID) &&
92
test_check_peerid "$PEERID"
93
'
94
@@ -97,13 +97,13 @@ test_ipfs_init_flags() {
97
98
echo "generating $RSA_BITS-bit RSA keypair...done" >rsa_expected &&
99
echo "peer identity: $PEERID" >>rsa_expected &&
100
- echo "initializing IPFS node at $IPFS_PATH" >>rsa_expected &&
100
+ echo "initializing IPFS node at $IPFS_DIR" >>rsa_expected &&
101
echo "to get started, enter:" >>rsa_expected &&
102
printf "\\n\\t$STARTFILE\\n\\n" >>rsa_expected &&
103
104
echo "generating ED25519 keypair...done" >ed25519_expected &&
105
echo "peer identity: $PEERID" >>ed25519_expected &&
106
- echo "initializing IPFS node at $IPFS_PATH" >>ed25519_expected &&
106
+ echo "initializing IPFS node at $IPFS_DIR" >>ed25519_expected &&
107
echo "to get started, enter:" >>ed25519_expected &&
108
printf "\\n\\t$STARTFILE\\n\\n" >>ed25519_expected &&
109
@@ -125,26 +125,26 @@ test_ipfs_init_flags() {
125
'
126
127
test_expect_success "clean up ipfs dir" '
128
- rm -rf "$IPFS_PATH"
128
+ rm -rf "$IPFS_DIR"
129
'
130
131
test_expect_success "'ipfs init --empty-repo' succeeds" '
132
RSA_BITS="2048" &&
133
case $TEST_ALG in
134
rsa)
135
- ipfs init --algorithm=rsa --bits="$RSA_BITS" --empty-repo >actual_init
135
+ ipfs init --repo-dir "$IPFS_DIR" --algorithm=rsa --bits="$RSA_BITS" --empty-repo >actual_init
136
;;
137
ed25519)
138
- ipfs init --algorithm=ed25519 --empty-repo >actual_init
138
+ ipfs init --repo-dir "$IPFS_DIR" --algorithm=ed25519 --empty-repo >actual_init
139
;;
140
*)
141
- ipfs init --empty-repo >actual_init
141
+ ipfs init --repo-dir "$IPFS_DIR" --empty-repo >actual_init
142
;;
143
esac
144
'
145
146
test_expect_success "ipfs peer id looks good" '
147
- PEERID=$(ipfs config Identity.PeerID) &&
147
+ PEERID=$(ipfs config --repo-dir "$IPFS_DIR" Identity.PeerID) &&
148
test_check_peerid "$PEERID"
149
'
150
@@ -152,11 +152,11 @@ test_ipfs_init_flags() {
152
153
echo "generating $RSA_BITS-bit RSA keypair...done" >rsa_expected &&
154
echo "peer identity: $PEERID" >>rsa_expected &&
155
- echo "initializing IPFS node at $IPFS_PATH" >>rsa_expected &&
155
+ echo "initializing IPFS node at $IPFS_DIR" >>rsa_expected &&
156
157
echo "generating ED25519 keypair...done" >ed25519_expected &&
158
echo "peer identity: $PEERID" >>ed25519_expected &&
159
- echo "initializing IPFS node at $IPFS_PATH" >>ed25519_expected &&
159
+ echo "initializing IPFS node at $IPFS_DIR" >>ed25519_expected &&
160
161
case $TEST_ALG in
162
rsa)
@@ -180,7 +180,7 @@ test_ipfs_init_flags() {
180
'
181
182
test_expect_success "clean up ipfs dir" '
183
- rm -rf "$IPFS_PATH"
183
+ rm -rf "$IPFS_DIR"
184
'
185
}
186
test_ipfs_init_flags 'ed25519'
@@ -190,70 +190,70 @@ test_ipfs_init_flags ''
190
# test init profiles
191
test_expect_success "'ipfs init --profile' with invalid profile fails" '
192
RSA_BITS="2048" &&
193
- test_must_fail ipfs init --profile=nonexistent_profile 2> invalid_profile_out
193
+ test_must_fail ipfs init --repo-dir "$IPFS_DIR" --profile=nonexistent_profile 2> invalid_profile_out
194
EXPECT="Error: invalid configuration profile: nonexistent_profile" &&
195
grep "$EXPECT" invalid_profile_out
196
'
197
198
test_expect_success "'ipfs init --profile' succeeds" '
199
RSA_BITS="2048" &&
200
- ipfs init --profile=server
200
+ ipfs init --repo-dir "$IPFS_DIR" --profile=server
201
'
202
203
test_expect_success "'ipfs config Swarm.AddrFilters' looks good" '
204
- ipfs config Swarm.AddrFilters > actual_config &&
204
+ ipfs config --repo-dir "$IPFS_DIR" Swarm.AddrFilters > actual_config &&
205
test $(cat actual_config | wc -l) = 18
206
'
207
208
test_expect_success "clean up ipfs dir" '
209
- rm -rf "$IPFS_PATH"
209
+ rm -rf "$IPFS_DIR"
210
'
211
212
test_expect_success "'ipfs init --profile=test' succeeds" '
213
RSA_BITS="2048" &&
214
- ipfs init --profile=test
214
+ ipfs init --repo-dir "$IPFS_DIR" --profile=test
215
'
216
217
test_expect_success "'ipfs config Bootstrap' looks good" '
218
- ipfs config Bootstrap > actual_config &&
218
+ ipfs config --repo-dir "$IPFS_DIR" Bootstrap > actual_config &&
219
test $(cat actual_config) = "[]"
220
'
221
222
test_expect_success "'ipfs config Addresses.API' looks good" '
223
- ipfs config Addresses.API > actual_config &&
223
+ ipfs config --repo-dir "$IPFS_DIR" Addresses.API > actual_config &&
224
test $(cat actual_config) = "/ip4/127.0.0.1/tcp/0"
225
'
226
227
test_expect_success "ipfs init from existing config succeeds" '
228
- export ORIG_PATH=$IPFS_PATH
229
- export IPFS_PATH=$(pwd)/.ipfs-clone
228
+ export ORIG_PATH=$IPFS_DIR
229
+ export IPFS_DIR=$(pwd)/.ipfs-clone
230
231
- ipfs init "$ORIG_PATH/config" &&
232
- ipfs config Addresses.API > actual_config &&
231
+ ipfs init --repo-dir "$IPFS_DIR" "$ORIG_PATH/config" &&
232
+ ipfs config --repo-dir "$IPFS_DIR" Addresses.API > actual_config &&
233
test $(cat actual_config) = "/ip4/127.0.0.1/tcp/0"
234
'
235
236
-test_expect_success "clean up ipfs clone dir and reset IPFS_PATH" '
237
- rm -rf "$IPFS_PATH" &&
238
- export IPFS_PATH=$ORIG_PATH
236
+test_expect_success "clean up ipfs clone dir and reset IPFS_DIR" '
237
+ rm -rf "$IPFS_DIR" &&
238
+ export IPFS_DIR=$ORIG_PATH
239
'
240
241
test_expect_success "clean up ipfs dir" '
242
- rm -rf "$IPFS_PATH"
242
+ rm -rf "$IPFS_DIR"
243
'
244
245
test_expect_success "'ipfs init --profile=lowpower' succeeds" '
246
RSA_BITS="2048" &&
247
- ipfs init --profile=lowpower
247
+ ipfs init --repo-dir "$IPFS_DIR" --profile=lowpower
248
'
249
250
test_expect_success "'ipfs config Discovery.Routing' looks good" '
251
- ipfs config Routing.Type > actual_config &&
251
+ ipfs config --repo-dir "$IPFS_DIR" Routing.Type > actual_config &&
252
test $(cat actual_config) = "dhtclient"
253
'
254
255
test_expect_success "clean up ipfs dir" '
256
- rm -rf "$IPFS_PATH"
256
+ rm -rf "$IPFS_DIR"
257
'
258
259
test_init_ipfs
@@ -261,7 +261,7 @@ test_init_ipfs
261
test_launch_ipfs_daemon
262
263
test_expect_success "ipfs init should not run while daemon is running" '
264
- test_must_fail ipfs init 2> daemon_running_err &&
264
+ test_must_fail ipfs init --repo-dir "$IPFS_DIR" 2> daemon_running_err &&
265
EXPECT="Error: ipfs daemon is running. please stop it to run this command" &&
266
grep "$EXPECT" daemon_running_err
267
'