t0060-daemon.sh 3.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/bin/sh
#
# Copyright (c) 2014 Juan Batiz-Benet
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test daemon command"

. lib/test-lib.sh

11

Jeromy's avatar
Jeromy committed
12
test_init_ipfs
Stephen Whitmore's avatar
Stephen Whitmore committed
13
test_launch_ipfs_daemon
14

Stephen Whitmore's avatar
Stephen Whitmore committed
15
# this errors if we didn't --init $IPFS_PATH correctly
16
test_expect_success "'ipfs config Identity.PeerID' works" '
17
  PEERID=$(ipfs config Identity.PeerID)
18 19
'

20 21 22 23
test_expect_success "'ipfs swarm addrs local' works" '
  ipfs swarm addrs local >local_addrs
'

24
test_expect_success "ipfs peer id looks good" '
25
  test_check_peerid "$PEERID"
26 27
'

rht's avatar
rht committed
28 29 30
# this is for checking SetAllowedOrigins race condition for the api and gateway
# See https://github.com/ipfs/go-ipfs/pull/1966
test_expect_success "ipfs API works with the correct allowed origin port" '
Jeromy's avatar
Jeromy committed
31
  curl -s -X GET -H "Origin:http://localhost:$API_PORT" -I "http://$API_ADDR/api/v0/version"
rht's avatar
rht committed
32 33 34
'

test_expect_success "ipfs gateway works with the correct allowed origin port" '
Jeromy's avatar
Jeromy committed
35
  curl -s -X GET -H "Origin:http://localhost:$GWAY_PORT" -I "http://$GWAY_ADDR/api/v0/version"
rht's avatar
rht committed
36 37
'

38
test_expect_success "ipfs daemon output looks good" '
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
39
  STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme" &&
40
  echo "Initializing daemon..." >expected_daemon &&
41
  sed "s/^/Swarm listening on /" local_addrs >>expected_daemon &&
42
  echo "API server listening on '$API_MADDR'" >>expected_daemon &&
43
  echo "Gateway (readonly) server listening on '$GWAY_MADDR'" >>expected_daemon &&
rht's avatar
rht committed
44
  echo "Daemon is ready" >>expected_daemon &&
45
  test_cmp expected_daemon actual_daemon
46 47
'

48 49 50
test_expect_success ".ipfs/ has been created" '
  test -d ".ipfs" &&
  test -f ".ipfs/config" &&
rht's avatar
rht committed
51 52 53
  test -d ".ipfs/datastore" &&
  test -d ".ipfs/blocks" ||
  test_fsh ls -al .ipfs
54 55
'

56 57 58 59 60 61 62
# begin same as in t0010

test_expect_success "ipfs version succeeds" '
	ipfs version >version.txt
'

test_expect_success "ipfs version output looks good" '
63
	egrep "^ipfs version [0-9]+\.[0-9]+\.[0-9]" version.txt >/dev/null ||
64 65 66 67 68 69 70 71
	test_fsh cat version.txt
'

test_expect_success "ipfs help succeeds" '
	ipfs help >help.txt
'

test_expect_success "ipfs help output looks good" '
72
	egrep -i "^Usage" help.txt >/dev/null &&
73
	egrep "ipfs .* <command>" help.txt >/dev/null ||
74 75 76
	test_fsh cat help.txt
'

Christian Couder's avatar
Christian Couder committed
77 78 79 80
# netcat (nc) is needed for the following test
test_expect_success "nc is available" '
	type nc >/dev/null
'
81

Christian Couder's avatar
Christian Couder committed
82
# check transport is encrypted
rht's avatar
rht committed
83
test_expect_success "transport should be encrypted" '
84
  nc -w 1 localhost $SWARM_PORT > swarmnc < ../t0060-data/mss-ls &&
85 86
  grep -q "/secio" swarmnc &&
  test_must_fail grep -q "/plaintext/1.0.0" swarmnc ||
87 88 89
	test_fsh cat swarmnc
'

90
test_expect_success "output from streaming commands works" '
Jeromy's avatar
Jeromy committed
91
	test_expect_code 28 curl -m 2 http://localhost:$API_PORT/api/v0/stats/bw\?poll=true > statsout
92 93 94 95 96 97 98 99 100
'

test_expect_success "output looks good" '
	grep TotalIn statsout > /dev/null &&
	grep TotalOut statsout > /dev/null &&
	grep RateIn statsout > /dev/null &&
	grep RateOut statsout >/dev/null
'

101 102
# end same as in t0010

103 104 105 106 107 108 109 110
test_expect_success "daemon is still running" '
  kill -0 $IPFS_PID
'

test_expect_success "'ipfs daemon' can be killed" '
  test_kill_repeat_10_sec $IPFS_PID
'

111
test_expect_success "'ipfs daemon' should be able to run with a pipe attached to stdin (issue #861)" '
Jeromy's avatar
Jeromy committed
112
	yes | ipfs daemon >stdin_daemon_out 2>stdin_daemon_err &
Jeromy's avatar
Jeromy committed
113
	DAEMON_PID=$!
Jeromy's avatar
Jeromy committed
114 115 116 117 118
	test_wait_for_file 20 100ms "$IPFS_PATH/api" &&
	test_set_address_vars stdin_daemon_out
'

test_expect_success "daemon with pipe eventually becomes live" '
119
  pollEndpoint -host='$API_MADDR' -ep=/version -v -tout=1s -tries=10 >stdin_poll_apiout 2>stdin_poll_apierr &&
Jeromy's avatar
Jeromy committed
120
  test_kill_repeat_10_sec $DAEMON_PID ||
121
  test_fsh cat stdin_daemon_out || test_fsh cat stdin_daemon_err || test_fsh cat stdin_poll_apiout || test_fsh cat stdin_poll_apierr
122 123
'

124
test_done