@cryptotaxi247 / kubo / commits / 24f0d020e

sharness: better config setting

Juan Batiz-Benet committed Feb 1, 2015 at 19:23 UTC 24f0d020e0261d8bce4c908077faecd26b786dd4
3 files changed +47 -11
test/sharness/lib/test-lib.sh
+45 -9
@@ -100,6 +100,30 @@ test_wait_open_tcp_port_10_sec() {
100 return 1
101 }
102
103 +
104 +# test_config_set helps us make sure _we really did set_ a config value.
105 +# it sets it and then tests it. This became elaborate because ipfs config
106 +# was setting really weird things and am not sure why.
107 +test_config_set() {
108 +
109 + # grab flags (like -bool in "ipfs config -bool")
110 + test_cfg_flags="" # unset in case.
111 + test "$#" = 3 && { test_cfg_flags=$1; shift; }
112 +
113 + test_cfg_key=$1
114 + test_cfg_val=$2
115 +
116 + # when verbose, tell the user what config values are being set
117 + test_cfg_cmd="ipfs config $test_cfg_flags \"$test_cfg_key\" \"$test_cfg_val\""
118 + test "$TEST_VERBOSE" = 1 && echo "$test_cfg_cmd"
119 +
120 + # ok try setting the config key/val pair.
121 + ipfs config $test_cfg_flags "$test_cfg_key" "$test_cfg_val"
122 + echo "$test_cfg_val" >cfg_set_expected
123 + ipfs config "$test_cfg_key" >cfg_set_actual
124 + test_cmp cfg_set_expected cfg_set_actual
125 +}
126 +
127 test_init_ipfs() {
128
129 test_expect_success "ipfs init succeeds" '
@@ -107,33 +131,45 @@ test_init_ipfs() {
131 ipfs init -b=1024 > /dev/null
132 '
133
110 - test_expect_success "prepare config" '
134 + test_expect_success "prepare config -- mounting and bootstrap rm" '
135 mkdir mountdir ipfs ipns &&
112 - ipfs config Mounts.IPFS "$(pwd)/ipfs" &&
113 - ipfs config Mounts.IPNS "$(pwd)/ipns" &&
114 - ipfs bootstrap rm --all
136 + test_config_set Mounts.IPFS "$(pwd)/ipfs" &&
137 + test_config_set Mounts.IPNS "$(pwd)/ipns" &&
138 + ipfs bootstrap rm --all ||
139 + fsh cat "\"$IPFS_PATH/config\""
140 '
141
142 }
143
144 test_config_ipfs_gateway_readonly() {
120 - test_expect_success "prepare config -- gateway readonly" '
121 - ipfs config "Addresses.Gateway" "/ip4/0.0.0.0/tcp/5002"
145 + if test "$1" == ""; then
146 + echo "must call with an address, for example:"
147 + echo 'test_config_ipfs_gateway_readonly "/ip4/0.0.0.0/tcp/5002"'
148 + return 1 # todo: find a better way to exit here.
149 + fi
150 +
151 + GWAY_ADDR=$1
152 + test_expect_success "prepare config -- gateway address" '
153 + test_config_set "Addresses.Gateway" "$GWAY_ADDR"
154 '
155 }
156
157 test_config_ipfs_gateway_writable() {
158 +
159 + test_config_ipfs_gateway_readonly $1
160 +
161 test_expect_success "prepare config -- gateway writable" '
127 - ipfs config "Addresses.Gateway" "/ip4/0.0.0.0/tcp/5002" &&
128 - ipfs config -bool "Gateway.Writable" true
162 + test_config_set -bool Gateway.Writable true ||
163 + fsh cat "\"$IPFS_PATH/config\""
164 '
165 }
166
167 test_launch_ipfs_daemon() {
168
169 ADDR_API="/ip4/127.0.0.1/tcp/5001"
135 - ADDR_GWAY=`ipfs config Addresses.Gateway`
170 NLINES="2"
171 +
172 + # ADDR_GWAY will be set if the test_config_ipfs_gateway_* funcs were called.
173 if test "$ADDR_GWAY" != ""; then
174 NLINES="3"
175 fi
test/sharness/t0110-gateway.sh
+1 -1
@@ -9,7 +9,7 @@ test_description="Test HTTP Gateway"
9 . lib/test-lib.sh
10
11 test_init_ipfs
12 -test_config_ipfs_gateway_readonly
12 +test_config_ipfs_gateway_readonly "/ip4/0.0.0.0/tcp/5002"
13 test_launch_ipfs_daemon
14
15 # TODO check both 5001 and 5002.
test/sharness/t0111-gateway-writable.sh
+1 -1
@@ -9,7 +9,7 @@ test_description="Test HTTP Gateway (Writable)"
9 . lib/test-lib.sh
10
11 test_init_ipfs
12 -test_config_ipfs_gateway_writable
12 +test_config_ipfs_gateway_writable "/ip4/0.0.0.0/tcp/5002"
13 test_launch_ipfs_daemon
14
15 test_expect_success "ipfs daemon listening to TCP port 5002" '