github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/test/sharness/t0060-daemon.sh (about)

     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  # TODO: randomize ports here once we add --config to ipfs daemon
    12  
    13  # this needs to be in a different test than "ipfs daemon --init" below
    14  test_expect_success "setup IPFS_PATH" '
    15    IPFS_PATH="$(pwd)/.ipfs" &&
    16    export IPFS_PATH
    17  '
    18  
    19  # NOTE: this should remove bootstrap peers (needs a flag)
    20  # TODO(cryptix):
    21  #  - we won't see daemon startup failure because we put the daemon in the background - fix: fork with exit code after api listen
    22  #  - also default ports: might clash with local clients. Failure in that case isn't clear as well because pollEndpoint just uses the already running node
    23  test_expect_success "ipfs daemon --init launches" '
    24    ipfs daemon --init >actual_daemon 2>daemon_err &
    25  '
    26  
    27  # this is like "'ipfs daemon' is ready" in test_launch_ipfs_daemon(), see test-lib.sh
    28  test_expect_success "initialization ended" '
    29    IPFS_PID=$! &&
    30    pollEndpoint -ep=/version -v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||
    31    test_fsh cat actual_daemon || test_fsh cat daemon_err || test_fsh cat poll_apierr || test_fsh cat poll_apiout
    32  '
    33  
    34  # this errors if daemon didnt --init $IPFS_PATH correctly
    35  test_expect_success "'ipfs config Identity.PeerID' works" '
    36    ipfs config Identity.PeerID >config_peerId
    37  '
    38  
    39  test_expect_success "'ipfs swarm addrs local' works" '
    40    ipfs swarm addrs local >local_addrs
    41  '
    42  
    43  
    44  # this is lifted straight from t0020-init.sh
    45  test_expect_success "ipfs peer id looks good" '
    46    PEERID=$(cat config_peerId) &&
    47    echo $PEERID | tr -dC "[:alnum:]" | wc -c | tr -d " " >actual_id &&
    48    echo "46" >expected_id &&
    49    test_cmp_repeat_10_sec expected_id actual_id
    50  '
    51  
    52  # This is like t0020-init.sh "ipfs init output looks good"
    53  #
    54  # Unfortunately the line:
    55  #
    56  #   API server listening on /ip4/127.0.0.1/tcp/5001
    57  #
    58  # sometimes doesn't show up, so we cannot use test_expect_success yet.
    59  #
    60  test_expect_success "ipfs daemon output looks good" '
    61    STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme" &&
    62    echo "Initializing daemon..." >expected_daemon &&
    63    echo "initializing ipfs node at $IPFS_PATH" >>expected_daemon &&
    64    echo "generating 2048-bit RSA keypair...done" >>expected_daemon &&
    65    echo "peer identity: $PEERID" >>expected_daemon &&
    66    echo "to get started, enter:" >>expected_daemon &&
    67    printf "\\n\\t$STARTFILE\\n\\n" >>expected_daemon &&
    68    cat local_addrs | sed "s/^/Swarm listening on /" >>expected_daemon &&
    69    echo "API server listening on /ip4/127.0.0.1/tcp/5001" >>expected_daemon &&
    70    echo "Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080" >>expected_daemon &&
    71    echo "Daemon is ready" >>expected_daemon &&
    72    test_cmp expected_daemon actual_daemon
    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" ||
    80    test_fsh ls -al .ipfs
    81  '
    82  
    83  # begin same as in t0010
    84  
    85  test_expect_success "ipfs version succeeds" '
    86  	ipfs version >version.txt
    87  '
    88  
    89  test_expect_success "ipfs version output looks good" '
    90  	cat version.txt | egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" >/dev/null ||
    91  	test_fsh cat version.txt
    92  '
    93  
    94  test_expect_success "ipfs help succeeds" '
    95  	ipfs help >help.txt
    96  '
    97  
    98  test_expect_success "ipfs help output looks good" '
    99  	cat help.txt | egrep -i "^Usage:" >/dev/null &&
   100  	cat help.txt | egrep "ipfs .* <command>" >/dev/null ||
   101  	test_fsh cat help.txt
   102  '
   103  
   104  # check transport is encrypted
   105  
   106  test_expect_success "transport should be encrypted" '
   107    nc -w 5 localhost 4001 >swarmnc &&
   108    grep -q "AES-256,AES-128" swarmnc &&
   109    test_must_fail grep -q "/ipfs/identify" swarmnc ||
   110  	test_fsh cat swarmnc
   111  '
   112  
   113  # end same as in t0010
   114  
   115  test_expect_success "daemon is still running" '
   116    kill -0 $IPFS_PID
   117  '
   118  
   119  test_expect_success "'ipfs daemon' can be killed" '
   120    test_kill_repeat_10_sec $IPFS_PID
   121  '
   122  
   123  test_expect_success "'ipfs daemon' should be able to run with a pipe attached to stdin (issue #861)" '
   124    yes | ipfs daemon --init >stdin_daemon_out 2>stdin_daemon_err &
   125    pollEndpoint -ep=/version -v -tout=1s -tries=10 >stdin_poll_apiout 2>stdin_poll_apierr &&
   126    test_kill_repeat_10_sec $! ||
   127    test_fsh cat stdin_daemon_out || test_fsh cat stdin_daemon_err || test_fsh cat stdin_poll_apiout || test_fsh cat stdin_poll_apierr
   128  '
   129  
   130  test_done