@cryptotaxi247 / kubo / commits / b883381b6

improved t0062-daemon-api.sh tests

License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>

Juan Batiz-Benet committed Aug 29, 2015 at 06:12 UTC b883381b6357d416879c4f6ccae16c2658782e13
1 file changed +77 -21
test/sharness/t0062-daemon-api.sh
+77 -21
@@ -10,7 +10,9 @@ test_description="Test daemon command"
10 test_init_ipfs
11
12 differentport=$((PORT_API + 1))
13 -differentapi="/ip4/127.0.0.1/tcp/$differentport"
13 +api_different="/ip4/127.0.0.1/tcp/$differentport"
14 +api_unreachable="/ip4/127.0.0.1/tcp/1"
15 +api_fromcfg=$(ipfs config Addresses.API)
16 peerid=$(ipfs config Identity.PeerID)
17
18 test_client() {
@@ -20,14 +22,30 @@ test_client() {
22 test_cmp expected actual
23 }
24
23 -test_expect_success "client should work when there is no api file and no --api is specified" '
25 +test_client_must_fail() {
26 + args="$@"
27 + echo "Error: api not running" >expected_err
28 + test_must_fail ipfs $args id -f="<id>" >actual 2>actual_err
29 + test_cmp expected_err actual_err
30 +}
31 +
32 +
33 +# first, test things without daemon, without /api file
34 +
35 +test_expect_success "client should work (daemon off, no /api file, no --api)" '
36 test_client
37 '
38
27 -test_expect_success "client should err when there is no api file and with --api is specified" '
28 - test_must_fail test_client --api "$differentapi"
39 +test_expect_success "client --api fromcfg should err (daemon off, no /api file)" '
40 + test_client_must_fail --api "$api_fromcfg"
41 '
42
43 +test_expect_success "client --api unreachable should err (daemon off, no /api file)" '
44 + test_client_must_fail --api "$api_unreachable"
45 +'
46 +
47 +# then, test things with daemon, with /api file
48 +
49 test_launch_ipfs_daemon
50
51 test_expect_success "'ipfs daemon' creates api file" '
@@ -39,42 +57,80 @@ test_expect_success "api file looks good" '
57 test_cmp expected .ipfs/api
58 '
59
42 -test_expect_success "client should err if client api != api file while daemon is on" '
43 - echo "Error: api not running" >expected &&
44 - test_must_fail ipfs --api "$differentapi" id 2>actual &&
45 - test_cmp expected actual
60 +test_expect_success "client should work (daemon on, /api file, no --api)" '
61 + test_client
62 '
63
64 +test_expect_success "client --api fromcfg should work (daemon used cfg) (daemon, /api file)" '
65 + test_client --api "$api_fromcfg"
66 +'
67 +
68 +test_expect_success "client --api unreachable should err (daemon, /api file)" '
69 + test_client_must_fail --api "$api_unreachable"
70 +'
71 +
72 +# then, test things without daemon, with /api file
73 +
74 test_kill_ipfs_daemon
75
50 -test_expect_success "client should err if client api != api file while daemon is off" '
51 - echo "Error: api not running" >expected &&
52 - test_must_fail ipfs --api "$differentapi" id 2>actual &&
53 - test_cmp expected actual
76 +test_expect_success "client should work (daemon off, /api file, no --api)" '
77 + test_client
78 +'
79 +
80 +test_expect_success "client --api fromcfg should err (daemon off, /api file)" '
81 + test_client_must_fail --api "$api_fromcfg"
82 '
83
84 +test_expect_success "client --api unreachable should err (daemon, /api file)" '
85 + test_client_must_fail --api "$api_unreachable"
86 +'
87 +
88 +# then, test things with daemon --api $api_different, with /api file
89 +
90 PORT_API=$differentport
57 -ADDR_API=$differentapi
91 +ADDR_API=$api_different
92
93 test_launch_ipfs_daemon --api "$ADDR_API"
94
61 -test_expect_success "'ipfs daemon' api option works" '
62 - printf "$differentapi" >expected &&
95 +test_expect_success "'ipfs daemon' --api option works" '
96 + printf "$api_different" >expected &&
97 test_cmp expected .ipfs/api
98 '
99
66 -test_expect_success "client should work if client api == api file, != cfg api while daemon is on" '
67 - test_client --api "$differentapi"
100 +test_expect_success "client should work (daemon on, /api file (different), no --api)" '
101 + test_client
102 '
103
70 -test_expect_success "client should read the api file while daemon is on" '
71 - test_client
104 +test_expect_success "client --api different should work (daemon on, /api file (different))" '
105 + test_client --api "$api_different"
106 +'
107 +
108 +test_expect_success "client --api fromcfg should err (daemon on, /api file (different))" '
109 + test_client_must_fail --api "$api_fromcfg"
110 +'
111 +
112 +test_expect_success "client --api unreachable should err (daemon, /api file)" '
113 + test_client_must_fail --api "$api_unreachable"
114 '
115
116 +# then, test things with daemon off, with /api file, for good measure.
117 +
118 test_kill_ipfs_daemon
119
76 -test_expect_success "client should work if there is api file while daemon is off" '
77 - ipfs id
120 +test_expect_success "client should work (daemon off, /api file (different), no --api)" '
121 + test_client
122 +'
123 +
124 +test_expect_success "client --api different should work (daemon on, /api file (different))" '
125 + test_client_must_fail --api "$api_different"
126 +'
127 +
128 +test_expect_success "client --api fromcfg should err (daemon on, /api file (different))" '
129 + test_client_must_fail --api "$api_fromcfg"
130 +'
131 +
132 +test_expect_success "client --api unreachable should err (daemon, /api file)" '
133 + test_client_must_fail --api "$api_unreachable"
134 '
135
136 test_done