@cryptotaxi247 / kubo / commits / dd265b7f0

Add test cases for ipfs api check

License: MIT Signed-off-by: rht <rhtbot@gmail.com>

rht committed Aug 27, 2015 at 15:41 UTC dd265b7f034488b6b4056a061276efe6baaeb530
3 files changed +78 -4
test/sharness/README.md
+2 -1
@@ -71,7 +71,8 @@ For example:
71 test_expect_success ".ipfs/ has been created" '
72 test -d ".ipfs" &&
73 test -f ".ipfs/config" &&
74 - test -d ".ipfs/datastore" ||
74 + test -d ".ipfs/datastore" &&
75 + test -d ".ipfs/blocks" ||
76 test_fsh ls -al .ipfs
77 '
78 ```
test/sharness/t0060-daemon.sh
+4 -3
@@ -75,8 +75,9 @@ test_expect_success "ipfs daemon output looks good" '
75 test_expect_success ".ipfs/ has been created" '
76 test -d ".ipfs" &&
77 test -f ".ipfs/config" &&
78 - test -d ".ipfs/datastore" ||
79 - test_fsh ls .ipfs
78 + test -d ".ipfs/datastore" &&
79 + test -d ".ipfs/blocks" ||
80 + test_fsh ls -al .ipfs
81 '
82
83 # begin same as in t0010
@@ -102,7 +103,7 @@ test_expect_success "ipfs help output looks good" '
103
104 # check transport is encrypted
105
105 -test_expect_success 'transport should be encrypted' '
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 ||
test/sharness/t0062-daemon-api.sh new
+72
@@ -0,0 +1,72 @@
1 +#!/bin/sh
2 +#
3 +# MIT Licensed; see the LICENSE file in this repository.
4 +#
5 +
6 +test_description="Test daemon command"
7 +
8 +. lib/test-lib.sh
9 +
10 +test_init_ipfs
11 +
12 +test_expect_success "client should work when there is no api file" '
13 + ipfs --api "$differentapi" id
14 +'
15 +
16 +test_launch_ipfs_daemon
17 +
18 +test_expect_success "'ipfs daemon' creates api file" '
19 + test -f ".ipfs/api"
20 +'
21 +
22 +differentport=$((PORT_API + 1))
23 +differentapi="/ip4/127.0.0.1/tcp/$differentport"
24 +
25 +test_expect_success "client should err if client api != api file while daemon is on" '
26 + echo "Error: api not running" >expected &&
27 + test_must_fail ipfs --api "$differentapi" id 2>actual &&
28 + test_cmp expected actual
29 +'
30 +
31 +test_kill_ipfs_daemon
32 +
33 +test_expect_success "client should err if client api != api file while daemon is off" '
34 + echo "Error: api not running" >expected &&
35 + test_must_fail ipfs --api "$differentapi" id 2>actual &&
36 + test_cmp expected actual
37 +'
38 +
39 +PORT_API=$differentport
40 +ADDR_API=$differentapi
41 +
42 +# test_launch_ipfs_daemon '--api "$ADDR_API"'
43 +
44 +#pasted from test_launch_ipfs_daemon because the above line doesn't work
45 +test_expect_success "'ipfs daemon' succeeds" '
46 + ipfs daemon --api $ADDR_API >actual_daemon 2>daemon_err &
47 +'
48 +
49 +# we say the daemon is ready when the API server is ready.
50 +test_expect_success "'ipfs daemon' is ready" '
51 + IPFS_PID=$! &&
52 + pollEndpoint -ep=/version -host=$ADDR_API -v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||
53 + test_fsh cat actual_daemon || test_fsh cat daemon_err || test_fsh cat poll_apierr || test_fsh cat poll_apiout
54 +'
55 +#end of "test_launch_ipfs_daemon
56 +
57 +test_expect_success "'ipfs daemon' api option works" '
58 + printf "$differentapi" > expected &&
59 + test_cmp expected .ipfs/api
60 +'
61 +
62 +test_expect_success "client should work if client api == api file, != cfg api while daemon is on" '
63 + ipfs --api "$differentapi" id
64 +'
65 +
66 +test_kill_ipfs_daemon
67 +
68 +test_expect_success "client should work if there is api file while daemon is off" '
69 + ipfs id
70 +'
71 +
72 +test_done