Skip to content

Commit 5d60b7c

Browse files
committed
cleanup
1 parent 8885034 commit 5d60b7c

File tree

2 files changed

+168
-168
lines changed

2 files changed

+168
-168
lines changed

sharness/lib/test-lib.sh

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,171 @@ test_repo_version() {
229229
test_cmp expected actual
230230
'
231231
}
232+
233+
test_install_ipfs_nd() {
234+
VERSION="$1"
235+
236+
# We have to change the PATH as ipfs-update might call fs-repo-migrations
237+
test_expect_success "'ipfs-update install' works for $VERSION" '
238+
ipfs-update --verbose install $VERSION > actual 2>&1 ||
239+
test_fsh cat actual
240+
'
241+
242+
test_expect_success "'ipfs-update install' output looks good" '
243+
grep "fetching ipfs version $VERSION" actual &&
244+
grep "installation complete." actual ||
245+
test_fsh cat actual
246+
'
247+
248+
test_expect_success "'ipfs-update version' works for $VERSION" '
249+
ipfs-update version > actual
250+
'
251+
252+
test_expect_success "'ipfs-update version' output looks good" '
253+
echo "$VERSION" >expected &&
254+
test_cmp expected actual
255+
'
256+
}
257+
258+
test_init_ipfs_nd() {
259+
260+
test_expect_success "ipfs init succeeds" '
261+
export IPFS_PATH="$(pwd)/.ipfs" &&
262+
ipfs init -b=1024 > /dev/null
263+
'
264+
265+
test_expect_success "prepare config -- mounting and bootstrap rm" '
266+
test_config_set Addresses.API "/ip4/127.0.0.1/tcp/0" &&
267+
test_config_set Addresses.Gateway "/ip4/127.0.0.1/tcp/0" &&
268+
test_config_set --json Addresses.Swarm "[
269+
\"/ip4/0.0.0.0/tcp/0\"
270+
]" &&
271+
ipfs bootstrap rm --all ||
272+
test_fsh cat "\"$IPFS_PATH/config\""
273+
'
274+
}
275+
276+
test_config_set() {
277+
278+
# grab flags (like --bool in "ipfs config --bool")
279+
test_cfg_flags="" # unset in case.
280+
test "$#" = 3 && { test_cfg_flags=$1; shift; }
281+
282+
test_cfg_key=$1
283+
test_cfg_val=$2
284+
285+
# when verbose, tell the user what config values are being set
286+
test_cfg_cmd="ipfs config $test_cfg_flags \"$test_cfg_key\" \"$test_cfg_val\""
287+
test "$TEST_VERBOSE" = 1 && echo "$test_cfg_cmd"
288+
289+
# ok try setting the config key/val pair.
290+
ipfs config $test_cfg_flags "$test_cfg_key" "$test_cfg_val"
291+
echo "$test_cfg_val" >cfg_set_expected
292+
ipfs config "$test_cfg_key" >cfg_set_actual
293+
test_cmp cfg_set_expected cfg_set_actual
294+
}
295+
296+
test_set_address_vars_nd() {
297+
daemon_output="$1"
298+
299+
test_expect_success "set up address variables" '
300+
API_MADDR=$(cat "$IPFS_PATH/api") &&
301+
API_ADDR=$(convert_tcp_maddr $API_MADDR) &&
302+
API_PORT=$(port_from_maddr $API_MADDR) &&
303+
304+
GWAY_MADDR=$(sed -n "s/^Gateway (.*) server listening on //p" "$daemon_output") &&
305+
GWAY_ADDR=$(convert_tcp_maddr $GWAY_MADDR) &&
306+
GWAY_PORT=$(port_from_maddr $GWAY_MADDR)
307+
'
308+
309+
if ipfs swarm addrs local >/dev/null 2>&1; then
310+
test_expect_success "set swarm address vars" '
311+
ipfs swarm addrs local > addrs_out &&
312+
SWARM_MADDR=$(grep "127.0.0.1" addrs_out) &&
313+
SWARM_PORT=$(port_from_maddr $SWARM_MADDR)
314+
'
315+
fi
316+
}
317+
318+
convert_tcp_maddr() {
319+
echo $1 | awk -F'/' '{ printf "%s:%s", $3, $5 }'
320+
}
321+
322+
port_from_maddr() {
323+
echo $1 | awk -F'/' '{ print $NF }'
324+
}
325+
326+
test_launch_ipfs_daemon() {
327+
328+
args="$@"
329+
330+
test "$TEST_ULIMIT_PRESET" != 1 && ulimit -n 1024
331+
332+
test_expect_success "'ipfs daemon' succeeds" '
333+
ipfs daemon $args >actual_daemon 2>daemon_err &
334+
'
335+
336+
# wait for api file to show up
337+
test_expect_success "api file shows up" '
338+
test_wait_for_file 20 100ms "$IPFS_PATH/api"
339+
'
340+
341+
test_set_address_vars_nd actual_daemon
342+
343+
# we say the daemon is ready when the API server is ready.
344+
test_expect_success "'ipfs daemon' is ready" '
345+
IPFS_PID=$! &&
346+
pollEndpoint -ep=/version -host=$API_MADDR -v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||
347+
test_fsh cat actual_daemon || test_fsh cat daemon_err || test_fsh cat poll_apierr || test_fsh cat poll_apiout
348+
'
349+
}
350+
351+
test_wait_for_file() {
352+
loops=$1
353+
delay=$2
354+
file=$3
355+
fwaitc=0
356+
while ! test -f "$file"
357+
do
358+
if test $fwaitc -ge $loops
359+
then
360+
echo "Error: timed out waiting for file: $file"
361+
return 1
362+
fi
363+
364+
go-sleep $delay
365+
fwaitc=`expr $fwaitc + 1`
366+
done
367+
}
368+
369+
370+
test_kill_repeat_10_sec() {
371+
# try to shut down once + wait for graceful exit
372+
kill $1
373+
for i in $(test_seq 1 100)
374+
do
375+
go-sleep 100ms
376+
! kill -0 $1 2>/dev/null && return
377+
done
378+
379+
# if not, try once more, which will skip graceful exit
380+
kill $1
381+
go-sleep 1s
382+
! kill -0 $1 2>/dev/null && return
383+
384+
# ok, no hope. kill it to prevent it messing with other tests
385+
kill -9 $1 2>/dev/null
386+
return 1
387+
}
388+
389+
test_kill_ipfs_daemon() {
390+
391+
test_expect_success "'ipfs daemon' is still running" '
392+
kill -0 $IPFS_PID
393+
'
394+
395+
test_expect_success "'ipfs daemon' can be killed" '
396+
test_kill_repeat_10_sec $IPFS_PID
397+
'
398+
}
399+

sharness/t0080-three-to-four.sh

Lines changed: 0 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -33,173 +33,6 @@ export GOPATH="$(pwd)/gopath"
3333
mkdir -p gopath/bin
3434
export PATH="../bin:$GOPATH/bin:$PATH"
3535

36-
test_install_ipfs_nd() {
37-
VERSION="$1"
38-
39-
# We have to change the PATH as ipfs-update might call fs-repo-migrations
40-
test_expect_success "'ipfs-update install' works for $VERSION" '
41-
ipfs-update --verbose install $VERSION > actual 2>&1 ||
42-
test_fsh cat actual
43-
'
44-
45-
test_expect_success "'ipfs-update install' output looks good" '
46-
grep "fetching ipfs version $VERSION" actual &&
47-
grep "installation complete." actual ||
48-
test_fsh cat actual
49-
'
50-
51-
test_expect_success "'ipfs-update version' works for $VERSION" '
52-
ipfs-update version > actual
53-
'
54-
55-
test_expect_success "'ipfs-update version' output looks good" '
56-
echo "$VERSION" >expected &&
57-
test_cmp expected actual
58-
'
59-
}
60-
61-
test_init_ipfs_nd() {
62-
63-
test_expect_success "ipfs init succeeds" '
64-
export IPFS_PATH="$(pwd)/.ipfs" &&
65-
ipfs init -b=1024 > /dev/null
66-
'
67-
68-
test_expect_success "prepare config -- mounting and bootstrap rm" '
69-
test_config_set Addresses.API "/ip4/127.0.0.1/tcp/0" &&
70-
test_config_set Addresses.Gateway "/ip4/127.0.0.1/tcp/0" &&
71-
test_config_set --json Addresses.Swarm "[
72-
\"/ip4/0.0.0.0/tcp/0\"
73-
]" &&
74-
ipfs bootstrap rm --all ||
75-
test_fsh cat "\"$IPFS_PATH/config\""
76-
'
77-
}
78-
79-
test_config_set() {
80-
81-
# grab flags (like --bool in "ipfs config --bool")
82-
test_cfg_flags="" # unset in case.
83-
test "$#" = 3 && { test_cfg_flags=$1; shift; }
84-
85-
test_cfg_key=$1
86-
test_cfg_val=$2
87-
88-
# when verbose, tell the user what config values are being set
89-
test_cfg_cmd="ipfs config $test_cfg_flags \"$test_cfg_key\" \"$test_cfg_val\""
90-
test "$TEST_VERBOSE" = 1 && echo "$test_cfg_cmd"
91-
92-
# ok try setting the config key/val pair.
93-
ipfs config $test_cfg_flags "$test_cfg_key" "$test_cfg_val"
94-
echo "$test_cfg_val" >cfg_set_expected
95-
ipfs config "$test_cfg_key" >cfg_set_actual
96-
test_cmp cfg_set_expected cfg_set_actual
97-
}
98-
99-
test_set_address_vars_nd() {
100-
daemon_output="$1"
101-
102-
test_expect_success "set up address variables" '
103-
API_MADDR=$(cat "$IPFS_PATH/api") &&
104-
API_ADDR=$(convert_tcp_maddr $API_MADDR) &&
105-
API_PORT=$(port_from_maddr $API_MADDR) &&
106-
107-
GWAY_MADDR=$(sed -n "s/^Gateway (.*) server listening on //p" "$daemon_output") &&
108-
GWAY_ADDR=$(convert_tcp_maddr $GWAY_MADDR) &&
109-
GWAY_PORT=$(port_from_maddr $GWAY_MADDR)
110-
'
111-
112-
if ipfs swarm addrs local >/dev/null 2>&1; then
113-
test_expect_success "set swarm address vars" '
114-
ipfs swarm addrs local > addrs_out &&
115-
SWARM_MADDR=$(grep "127.0.0.1" addrs_out) &&
116-
SWARM_PORT=$(port_from_maddr $SWARM_MADDR)
117-
'
118-
fi
119-
}
120-
121-
convert_tcp_maddr() {
122-
echo $1 | awk -F'/' '{ printf "%s:%s", $3, $5 }'
123-
}
124-
125-
port_from_maddr() {
126-
echo $1 | awk -F'/' '{ print $NF }'
127-
}
128-
129-
test_launch_ipfs_daemon() {
130-
131-
args="$@"
132-
133-
test "$TEST_ULIMIT_PRESET" != 1 && ulimit -n 1024
134-
135-
test_expect_success "'ipfs daemon' succeeds" '
136-
ipfs daemon $args >actual_daemon 2>daemon_err &
137-
'
138-
139-
# wait for api file to show up
140-
test_expect_success "api file shows up" '
141-
test_wait_for_file 20 100ms "$IPFS_PATH/api"
142-
'
143-
144-
test_set_address_vars_nd actual_daemon
145-
146-
# we say the daemon is ready when the API server is ready.
147-
test_expect_success "'ipfs daemon' is ready" '
148-
IPFS_PID=$! &&
149-
pollEndpoint -ep=/version -host=$API_MADDR -v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||
150-
test_fsh cat actual_daemon || test_fsh cat daemon_err || test_fsh cat poll_apierr || test_fsh cat poll_apiout
151-
'
152-
}
153-
154-
test_wait_for_file() {
155-
loops=$1
156-
delay=$2
157-
file=$3
158-
fwaitc=0
159-
while ! test -f "$file"
160-
do
161-
if test $fwaitc -ge $loops
162-
then
163-
echo "Error: timed out waiting for file: $file"
164-
return 1
165-
fi
166-
167-
go-sleep $delay
168-
fwaitc=`expr $fwaitc + 1`
169-
done
170-
}
171-
172-
173-
test_kill_repeat_10_sec() {
174-
# try to shut down once + wait for graceful exit
175-
kill $1
176-
for i in $(test_seq 1 100)
177-
do
178-
go-sleep 100ms
179-
! kill -0 $1 2>/dev/null && return
180-
done
181-
182-
# if not, try once more, which will skip graceful exit
183-
kill $1
184-
go-sleep 1s
185-
! kill -0 $1 2>/dev/null && return
186-
187-
# ok, no hope. kill it to prevent it messing with other tests
188-
kill -9 $1 2>/dev/null
189-
return 1
190-
}
191-
192-
test_kill_ipfs_daemon() {
193-
194-
test_expect_success "'ipfs daemon' is still running" '
195-
kill -0 $IPFS_PID
196-
'
197-
198-
test_expect_success "'ipfs daemon' can be killed" '
199-
test_kill_repeat_10_sec $IPFS_PID
200-
'
201-
}
202-
20336

20437
test_install_ipfs_nd "v0.4.2"
20538

@@ -269,7 +102,6 @@ test_expect_success "get pin lists" '
269102
ipfs pin ls --type=indirect | sort > start_ind_pins
270103
'
271104

272-
273105
test_kill_ipfs_daemon
274106

275107
test_install_ipfs_nd "v0.4.3-dev"

0 commit comments

Comments
 (0)