| 1 | #!/usr/bin/env bash |
| 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 --init command" |
| 8 | |
| 9 | . lib/test-lib.sh |
| 10 | |
| 11 | # We don't want the normal test_init_ipfs but we need to make sure the |
| 12 | # IPFS_PATH is set correctly. |
| 13 | export IPFS_PATH="$(pwd)/.ipfs" |
| 14 | |
| 15 | # safety check since we will be removing the directory |
| 16 | if [ -e "$IPFS_PATH" ]; then |
| 17 | echo "$IPFS_PATH exists" |
| 18 | exit 1 |
| 19 | fi |
| 20 | |
| 21 | test_ipfs_daemon_init() { |
| 22 | # Doing it manually since we want to launch the daemon with an |
| 23 | # empty or non-existent repo; the normal |
| 24 | # test_launch_ipfs_daemon does not work since it assumes the |
| 25 | # repo was created a particular way with regard to the API |
| 26 | # server. |
| 27 | |
| 28 | test_expect_success "'ipfs daemon --init' succeeds" ' |
| 29 | ipfs daemon --init --init-profile=test >actual_daemon 2>daemon_err & |
| 30 | IPFS_PID=$! |
| 31 | sleep 2 && |
| 32 | if ! kill -0 $IPFS_PID; then cat daemon_err; return 1; fi |
| 33 | ' |
| 34 | |
| 35 | test_expect_success "'ipfs daemon' can be killed" ' |
| 36 | test_kill_repeat_10_sec $IPFS_PID |
| 37 | ' |
| 38 | } |
| 39 | |
| 40 | test_expect_success "remove \$IPFS_PATH dir" ' |
| 41 | rm -rf "$IPFS_PATH" |
| 42 | ' |
| 43 | test_ipfs_daemon_init |
| 44 | |
| 45 | test_expect_success "create empty \$IPFS_PATH dir" ' |
| 46 | rm -rf "$IPFS_PATH" && |
| 47 | mkdir "$IPFS_PATH" |
| 48 | ' |
| 49 | |
| 50 | test_ipfs_daemon_init |
| 51 | |
| 52 | test_done |