Fix and refactor daemon api test
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
rht committed
Aug 29, 2015 at 22:10 UTC
1198564ca3885be97212fbf22ac4524ad6250e56
1 file changed
+39
-63
test/sharness/t0062-daemon-api.sh
+39
-63
@@ -29,20 +29,44 @@ test_client_must_fail() {
29
test_cmp expected_err actual_err
30
}
31
32
+test_client_suite() {
33
+ state="$1"
34
+ cfg_success="$2"
35
+ diff_success="$3"
36
+ # must always work
37
+ test_expect_success "client should work $state" '
38
+ test_client
39
+ '
40
+
41
+ # must always err
42
+ test_expect_success "client --api unreachable should err $state" '
43
+ test_client_must_fail --api "$api_unreachable"
44
+ '
45
+
46
+ if [ "$cfg_success" = true ]; then
47
+ test_expect_success "client --api fromcfg should work $state" '
48
+ test_client --api "$api_fromcfg"
49
+ '
50
+ else
51
+ test_expect_success "client --api fromcfg should err $state" '
52
+ test_client_must_fail --api "$api_fromcfg"
53
+ '
54
+ fi
55
+
56
+ if [ "$diff_success" = true ]; then
57
+ test_expect_success "client --api different should work $state" '
58
+ test_client --api "$api_different"
59
+ '
60
+ else
61
+ test_expect_success "client --api different should err $state" '
62
+ test_client_must_fail --api "$api_different"
63
+ '
64
+ fi
65
+ }
66
67
# first, test things without daemon, without /api file
68
+test_client_suite "(daemon off, no --api, no /api file)" false false
69
35
-test_expect_success "client should work (daemon off, no /api file, no --api)" '
36
- test_client
37
-'
38
-
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
-'
70
71
# then, test things with daemon, with /api file
72
@@ -57,33 +81,13 @@ test_expect_success "api file looks good" '
81
test_cmp expected .ipfs/api
82
'
83
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
-'
84
+test_client_suite "(daemon on, no --api, /api file from cfg)" true false
85
86
# then, test things without daemon, with /api file
87
88
test_kill_ipfs_daemon
89
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
-'
90
+test_client_suite "(daemon off, no --api, /api file from cfg)" false false
91
92
# then, test things with daemon --api $api_different, with /api file
93
@@ -97,40 +101,12 @@ test_expect_success "'ipfs daemon' --api option works" '
101
test_cmp expected .ipfs/api
102
'
103
100
-test_expect_success "client should work (daemon on, /api file (different), no --api)" '
101
- test_client
102
-'
103
-
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
-'
104
+test_client_suite "(daemon on, /api file different)" false true
105
106
# then, test things with daemon off, with /api file, for good measure.
107
108
test_kill_ipfs_daemon
109
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
-'
110
+test_client_suite "(daemon off, /api file different)" false false
111
112
test_done