@cryptotaxi247 / kubo / commits / 3e96f4810

test: added daemon --init test

Juan Batiz-Benet committed Nov 18, 2014 at 08:18 UTC 3e96f4810b5b966ba7df6eed983db33f67298f44
2 files changed +68
test/lib/test-lib.sh
+12
@@ -39,6 +39,18 @@ test_cmp_repeat_10_sec() {
39 test_cmp "$1" "$2"
40 }
41
42 +test_wait_output_n_lines_20_sec() {
43 + echo "$2" >expected_waitn
44 + for i in 1 2 3 4 5 6 7 8 9 10
45 + do
46 + cat "$1" | wc -l | tr -d " " >actual_waitn
47 + test_cmp "expected_waitn" "actual_waitn" && return
48 + sleep 2
49 + done
50 + cat "$1" | wc -l | tr -d " " >actual_waitn
51 + test_cmp "expected_waitn" "actual_waitn"
52 +}
53 +
54 test_launch_ipfs_mount() {
55
56 test_expect_success "ipfs init succeeds" '
test/t0060-daemon.sh new
+56
@@ -0,0 +1,56 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2014 Juan Batiz-Benet
4 +# MIT Licensed; see the LICENSE file in this repository.
5 +#
6 +
7 +test_description="Test daemon command"
8 +
9 +. lib/test-lib.sh
10 +
11 +test_expect_success "ipfs daemon --init launches" '
12 + export IPFS_DIR="$(pwd)/.go-ipfs" &&
13 + ipfs daemon --init 2>&1 >actual_init &
14 +'
15 +
16 +# this is because we have no way of knowing the daemon is done except look at
17 +# output. but we can't yet compare it because we dont have the peer ID (config)
18 +test_expect_success "initialization ended" '
19 + IPFS_PID=$! &&
20 + test_wait_output_n_lines_20_sec actual_init 6
21 +'
22 +
23 +# this is lifted straight from t0020-init.sh
24 +test_expect_success "ipfs peer id looks good" '
25 + PEERID=$(ipfs config Identity.PeerID) &&
26 + echo $PEERID | tr -dC "[:alnum:]" | wc -c | tr -d " " >actual &&
27 + echo "46" >expected &&
28 + test_cmp_repeat_10_sec expected actual
29 +'
30 +
31 +# note this is almost the same as t0020-init.sh "ipfs init output looks good"
32 +test_expect_success "ipfs daemon output looks good" '
33 + STARTHASH="QmYpv2VEsxzTTXRYX3PjDg961cnJE3kY1YDXLycHGQ3zZB" &&
34 + echo "initializing ipfs node at $IPFS_DIR" >expected &&
35 + echo "generating key pair...done" >>expected &&
36 + echo "peer identity: $PEERID" >>expected &&
37 + echo "\nto get started, enter: ipfs cat $STARTHASH" >>expected &&
38 + echo "daemon listening on /ip4/127.0.0.1/tcp/5001" >>expected &&
39 + test_cmp_repeat_10_sec expected actual_init
40 +'
41 +
42 +test_expect_success ".go-ipfs/ has been created" '
43 + test -d ".go-ipfs" &&
44 + test -f ".go-ipfs/config" &&
45 + test -d ".go-ipfs/datastore"
46 +'
47 +
48 +test_expect_success "daemon is still running" '
49 + kill -0 $IPFS_PID
50 +'
51 +
52 +test_expect_success "'ipfs daemon' can be killed" '
53 + test_kill_repeat_10_sec $IPFS_PID
54 +'
55 +
56 +test_done