Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
0c7595b6
提交
0c7595b6
authored
2月 11, 2016
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use port zero for all ipfs daemon addresses in sharness testing
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
72176379
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
107 行增加
和
128 行删除
+107
-128
test-lib.sh
test/sharness/lib/test-lib.sh
+54
-52
t0040-add-and-cat.sh
test/sharness/t0040-add-and-cat.sh
+1
-1
t0061-daemon-opts.sh
test/sharness/t0061-daemon-opts.sh
+9
-6
t0062-daemon-api.sh
test/sharness/t0062-daemon-api.sh
+32
-56
t0110-gateway.sh
test/sharness/t0110-gateway.sh
+2
-3
t0111-gateway-writeable.sh
test/sharness/t0111-gateway-writeable.sh
+4
-4
t0112-gateway-cors.sh
test/sharness/t0112-gateway-cors.sh
+2
-3
t0121-bootstrap-iptb.sh
test/sharness/t0121-bootstrap-iptb.sh
+1
-1
t0230-channel-streaming-http-content-type.sh
test/sharness/t0230-channel-streaming-http-content-type.sh
+2
-2
没有找到文件。
test/sharness/lib/test-lib.sh
浏览文件 @
0c7595b6
...
@@ -125,29 +125,6 @@ test_config_set() {
...
@@ -125,29 +125,6 @@ test_config_set() {
test_init_ipfs
()
{
test_init_ipfs
()
{
# we have a problem where initializing daemons with the same api port
# often fails-- it hangs indefinitely. The proper solution is to make
# ipfs pick an unused port for the api on startup, and then use that.
# Unfortunately, ipfs doesnt yet know how to do this-- the api port
# must be specified. Until ipfs learns how to do this, we must use
# specific port numbers, which may still fail but less frequently
# if we at least use different ones.
# Using RANDOM like this is clearly wrong-- it samples with replacement
# and it doesnt even check the port is unused. this is a trivial stop gap
# until the proper solution is implemented.
RANDOM
=
$$
PORT_API
=
$((
RANDOM
%
3000
+
5100
))
ADDR_API
=
"/ip4/127.0.0.1/tcp/
$PORT_API
"
PORT_GWAY
=
$((
RANDOM
%
3000
+
8100
))
ADDR_GWAY
=
"/ip4/127.0.0.1/tcp/
$PORT_GWAY
"
PORT_SWARM
=
$((
RANDOM
%
3000
+
12000
))
ADDR_SWARM
=
"[
\"
/ip4/0.0.0.0/tcp/
$PORT_SWARM
\"
]"
# we set the Addresses.API config variable.
# we set the Addresses.API config variable.
# the cli client knows to use it, so only need to set.
# the cli client knows to use it, so only need to set.
...
@@ -162,40 +139,42 @@ test_init_ipfs() {
...
@@ -162,40 +139,42 @@ test_init_ipfs() {
mkdir mountdir ipfs ipns &&
mkdir mountdir ipfs ipns &&
test_config_set Mounts.IPFS "$(pwd)/ipfs" &&
test_config_set Mounts.IPFS "$(pwd)/ipfs" &&
test_config_set Mounts.IPNS "$(pwd)/ipns" &&
test_config_set Mounts.IPNS "$(pwd)/ipns" &&
test_config_set Addresses.API "$ADDR_API" &&
test_config_set Addresses.API "/ip4/127.0.0.1/tcp/0" &&
test_config_set Addresses.Gateway "$ADDR_GWAY" &&
test_config_set Addresses.Gateway "/ip4/127.0.0.1/tcp/0" &&
test_config_set --json Addresses.Swarm "$ADDR_SWARM" &&
test_config_set --json Addresses.Swarm "[
\"/ip4/0.0.0.0/tcp/0\"
]" &&
ipfs bootstrap rm --all ||
ipfs bootstrap rm --all ||
test_fsh cat "\"$IPFS_PATH/config\""
test_fsh cat "\"$IPFS_PATH/config\""
'
'
}
}
test_config_ipfs_gateway_readonly
()
{
ADDR_GWAY
=
$1
test_expect_success
"prepare config -- gateway address"
'
test "$ADDR_GWAY" != "" &&
test_config_set "Addresses.Gateway" "$ADDR_GWAY"
'
# tell the user what's going on if they messed up the call.
if
test
"$#"
=
0
;
then
echo
"# Error: must call with an address, for example:"
echo
'# test_config_ipfs_gateway_readonly "/ip4/0.0.0.0/tcp/5002"'
echo
'#'
fi
}
test_config_ipfs_gateway_writable
()
{
test_config_ipfs_gateway_writable
()
{
test_config_ipfs_gateway_readonly
$1
test_expect_success
"prepare config -- gateway writable"
'
test_expect_success
"prepare config -- gateway writable"
'
test_config_set --bool Gateway.Writable true ||
test_config_set --bool Gateway.Writable true ||
test_fsh cat "\"$IPFS_PATH/config\""
test_fsh cat "\"$IPFS_PATH/config\""
'
'
}
}
test_wait_for_file
()
{
loops
=
$1
delay
=
$2
file
=
$3
fwaitc
=
0
while
!
test
-f
"
$file
"
do
if
test
$fwaitc
-ge
$loops
then
echo
"Error: timed out waiting for file:
$file
"
return
1
fi
go-sleep
$delay
fwaitc
=
`
expr
$fwaitc
+ 1
`
done
}
test_launch_ipfs_daemon
()
{
test_launch_ipfs_daemon
()
{
args
=
"
$@
"
args
=
"
$@
"
...
@@ -204,19 +183,34 @@ test_launch_ipfs_daemon() {
...
@@ -204,19 +183,34 @@ test_launch_ipfs_daemon() {
ipfs daemon $args >actual_daemon 2>daemon_err &
ipfs daemon $args >actual_daemon 2>daemon_err &
'
'
# wait for api file to show up
test_expect_success
"api file shows up"
'
test_wait_for_file 20 100ms "$IPFS_PATH/api"
'
test_expect_success
"set up address variables"
'
API_MADDR=$(cat "$IPFS_PATH/api") &&
API_ADDR=$(convert_tcp_maddr $API_MADDR) &&
API_PORT=$(port_from_maddr $API_MADDR) &&
GWAY_MADDR=$(sed -n "s/^Gateway (.*) server listening on //p" actual_daemon) &&
GWAY_ADDR=$(convert_tcp_maddr $GWAY_MADDR) &&
GWAY_PORT=$(port_from_maddr $GWAY_MADDR)
'
test_expect_success
"set swarm address vars"
'
ipfs swarm addrs local > addrs_out &&
SWARM_MADDR=$(grep "127.0.0.1" addrs_out) &&
SWARM_PORT=$(port_from_maddr $SWARM_MADDR)
'
# we say the daemon is ready when the API server is ready.
# we say the daemon is ready when the API server is ready.
test_expect_success
"'ipfs daemon' is ready"
'
test_expect_success
"'ipfs daemon' is ready"
'
IPFS_PID=$! &&
IPFS_PID=$! &&
pollEndpoint -ep=/version -host=$A
DDR_API
-v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||
pollEndpoint -ep=/version -host=$A
PI_MADDR
-v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||
test_fsh cat actual_daemon || test_fsh cat daemon_err || test_fsh cat poll_apierr || test_fsh cat poll_apiout
test_fsh cat actual_daemon || test_fsh cat daemon_err || test_fsh cat poll_apierr || test_fsh cat poll_apiout
'
'
if
test
"
$ADDR_GWAY
"
!=
""
;
then
test_expect_success
"'ipfs daemon' output includes Gateway address"
'
pollEndpoint -ep=/version -host=$ADDR_GWAY -v -tout=1s -tries=60 2>poll_gwerr > poll_gwout ||
test_fsh cat daemon_err || test_fsh cat poll_gwerr || test_fsh cat poll_gwout
'
fi
}
}
do_umount
()
{
do_umount
()
{
...
@@ -365,3 +359,11 @@ test_check_peerid() {
...
@@ -365,3 +359,11 @@ test_check_peerid() {
return
1
return
1
}
}
}
}
convert_tcp_maddr
()
{
echo
$1
| awk
-F
'/'
'{ printf "%s:%s", $3, $5 }'
}
port_from_maddr
()
{
echo
$1
| awk
-F
'/'
'{ print $NF }'
}
test/sharness/t0040-add-and-cat.sh
浏览文件 @
0c7595b6
...
@@ -328,7 +328,7 @@ test_add_cat_5MB
...
@@ -328,7 +328,7 @@ test_add_cat_5MB
test_add_cat_expensive
test_add_cat_expensive
test_add_named_pipe
" Post http://
127.0.0.1:
$PORT_API
/api/v0/add?encoding=json&progress=true&r=true&stream-channels=true:"
test_add_named_pipe
" Post http://
$API_ADDR
/api/v0/add?encoding=json&progress=true&r=true&stream-channels=true:"
test_kill_ipfs_daemon
test_kill_ipfs_daemon
...
...
test/sharness/t0061-daemon-opts.sh
浏览文件 @
0c7595b6
...
@@ -13,21 +13,24 @@ test_init_ipfs
...
@@ -13,21 +13,24 @@ test_init_ipfs
test_launch_ipfs_daemon
--unrestricted-api
--disable-transport-encryption
test_launch_ipfs_daemon
--unrestricted-api
--disable-transport-encryption
gwyport
=
$PORT_GWAY
test_expect_success
"convert addresses from multiaddrs"
'
apiport
=
$PORT_API
'
gwyaddr
=
$GWAY_ADDR
apiaddr
=
$API_ADDR
test_expect_success
'api gateway should be unrestricted'
'
test_expect_success
'api gateway should be unrestricted'
'
echo "hello mars :$gwy
port :$apiport
" >expected &&
echo "hello mars :$gwy
addr :$apiaddr
" >expected &&
HASH=$(ipfs add -q expected) &&
HASH=$(ipfs add -q expected) &&
curl -sfo actual1 "http://
127.0.0.1:$gwyport
/ipfs/$HASH" &&
curl -sfo actual1 "http://
$gwyaddr
/ipfs/$HASH" &&
curl -sfo actual2 "http://
127.0.0.1:$apiport
/ipfs/$HASH" &&
curl -sfo actual2 "http://
$apiaddr
/ipfs/$HASH" &&
test_cmp expected actual1 &&
test_cmp expected actual1 &&
test_cmp expected actual2
test_cmp expected actual2
'
'
# Odd. this fails here, but the inverse works on t0060-daemon.
# Odd. this fails here, but the inverse works on t0060-daemon.
test_expect_success
'transport should be unencrypted'
'
test_expect_success
'transport should be unencrypted'
'
go-sleep 0.5s | nc localhost "$
PORT_SWARM
" >swarmnc &&
go-sleep 0.5s | nc localhost "$
SWARM_PORT
" >swarmnc &&
test_must_fail grep -q "AES-256,AES-128" swarmnc &&
test_must_fail grep -q "AES-256,AES-128" swarmnc &&
grep -q "/multistream/1.0.0" swarmnc ||
grep -q "/multistream/1.0.0" swarmnc ||
test_fsh cat swarmnc
test_fsh cat swarmnc
...
...
test/sharness/t0062-daemon-api.sh
浏览文件 @
0c7595b6
...
@@ -9,65 +9,65 @@ test_description="Test daemon command"
...
@@ -9,65 +9,65 @@ test_description="Test daemon command"
test_init_ipfs
test_init_ipfs
differentport
=
$((
PORT_API
+
1
))
differentport
=
$((
API_PORT
+
1
))
api_
different
=
"/ip4/127.0.0.1/tcp/
$differentport
"
api_
other
=
"/ip4/127.0.0.1/tcp/
$differentport
"
api_unreachable
=
"/ip4/127.0.0.1/tcp/1"
api_unreachable
=
"/ip4/127.0.0.1/tcp/1"
test_expect_success
"config setup"
'
test_expect_success
"config setup"
'
api_fromcfg=$(ipfs config Addresses.API) &&
peerid=$(ipfs config Identity.PeerID) &&
peerid=$(ipfs config Identity.PeerID) &&
test_check_peerid "$peerid"
test_check_peerid "$peerid"
'
'
test_client
()
{
test_client
()
{
printf
"
$peerid
"
>
expected
&&
opts
=
"
$@
"
ipfs
"
$@
"
id
-f
=
"<id>"
>
actual
&&
echo
"OPTS = "
$opts
test_cmp expected actual
test_expect_success
"client must work properly
$state
"
'
printf "$peerid" >expected &&
ipfs id -f="<id>" $opts >actual &&
test_cmp expected actual
'
}
}
test_client_must_fail
()
{
test_client_must_fail
()
{
echo
"Error: api not running"
>
expected_err
&&
opts
=
"
$@
"
test_must_fail ipfs
"
$@
"
id
-f
=
"<id>"
>
actual 2>actual_err
&&
echo
"OPTS = "
$opts
test_cmp expected_err actual_err
test_expect_success
"client should fail
$state
"
'
echo "Error: api not running" >expected_err &&
test_must_fail ipfs id -f="<id>" $opts >actual 2>actual_err &&
test_cmp expected_err actual_err
'
}
}
test_client_suite
()
{
test_client_suite
()
{
state
=
"
$1
"
state
=
"
$1
"
cfg_success
=
"
$2
"
cfg_success
=
"
$2
"
diff_success
=
"
$3
"
diff_success
=
"
$3
"
api_fromcfg
=
"
$4
"
api_different
=
"
$5
"
# must always work
# must always work
test_expect_success
"client should work
$state
"
'
test_client
test_client
'
# must always err
# must always err
test_expect_success
"client --api unreachable should err
$state
"
'
test_client_must_fail
--api
"
$api_unreachable
"
test_client_must_fail --api "$api_unreachable"
'
if
[
"
$cfg_success
"
=
true
]
;
then
if
[
"
$cfg_success
"
=
true
]
;
then
test_expect_success
"client --api fromcfg should work
$state
"
'
test_client
--api
"
$api_fromcfg
"
test_client --api "$api_fromcfg"
'
else
else
test_expect_success
"client --api fromcfg should err
$state
"
'
test_client_must_fail
--api
"
$api_fromcfg
"
test_client_must_fail --api "$api_fromcfg"
'
fi
fi
if
[
"
$diff_success
"
=
true
]
;
then
if
[
"
$diff_success
"
=
true
]
;
then
test_expect_success
"client --api different should work
$state
"
'
test_client
--api
"
$api_different
"
test_client --api "$api_different"
'
else
else
test_expect_success
"client --api different should err
$state
"
'
test_client_must_fail
--api
"
$api_different
"
test_client_must_fail --api "$api_different"
'
fi
fi
}
}
# first, test things without daemon, without /api file
# first, test things without daemon, without /api file
test_client_suite
"(daemon off, no --api, no /api file)"
false false
# with no daemon, everything should fail
# (using unreachable because API_MADDR doesnt get set until daemon start)
test_client_suite
"(daemon off, no --api, no /api file)"
false false
"
$api_unreachable
"
"
$api_other
"
# then, test things with daemon, with /api file
# then, test things with daemon, with /api file
...
@@ -78,37 +78,13 @@ test_expect_success "'ipfs daemon' creates api file" '
...
@@ -78,37 +78,13 @@ test_expect_success "'ipfs daemon' creates api file" '
test -f ".ipfs/api"
test -f ".ipfs/api"
'
'
test_expect_success
"api file looks good"
'
test_client_suite
"(daemon on, no --api, /api file from cfg)"
true false
"
$API_MADDR
"
"
$api_other
"
printf "$ADDR_API" >expected &&
test_cmp expected .ipfs/api
'
test_client_suite
"(daemon on, no --api, /api file from cfg)"
true false
# then, test things without daemon, with /api file
# then, test things without daemon, with /api file
test_kill_ipfs_daemon
test_kill_ipfs_daemon
test_client_suite
"(daemon off, no --api, /api file from cfg)"
false false
# again, both should fail
test_client_suite
"(daemon off, no --api, /api file from cfg)"
false false
"
$API_MADDR
"
"
$api_other
"
# then, test things with daemon --api $api_different, with /api file
PORT_API
=
$differentport
ADDR_API
=
$api_different
test_launch_ipfs_daemon
--api
"
$ADDR_API
"
test_expect_success
"'ipfs daemon' --api option works"
'
printf "$api_different" >expected &&
test_cmp expected .ipfs/api
'
test_client_suite
"(daemon on, /api file different)"
false true
# then, test things with daemon off, with /api file, for good measure.
test_kill_ipfs_daemon
test_client_suite
"(daemon off, /api file different)"
false false
test_done
test_done
test/sharness/t0110-gateway.sh
浏览文件 @
0c7595b6
...
@@ -9,11 +9,10 @@ test_description="Test HTTP Gateway"
...
@@ -9,11 +9,10 @@ test_description="Test HTTP Gateway"
.
lib/test-lib.sh
.
lib/test-lib.sh
test_init_ipfs
test_init_ipfs
test_config_ipfs_gateway_readonly
$ADDR_GWAY
test_launch_ipfs_daemon
test_launch_ipfs_daemon
port
=
$
PORT_GWAY
port
=
$
GWAY_PORT
apiport
=
$
PORT_API
apiport
=
$
API_PORT
# TODO check both 5001 and 5002.
# TODO check both 5001 and 5002.
# 5001 should have a readable gateway (part of the API)
# 5001 should have a readable gateway (part of the API)
...
...
test/sharness/t0111-gateway-writeable.sh
浏览文件 @
0c7595b6
...
@@ -9,18 +9,18 @@ test_description="Test HTTP Gateway (Writable)"
...
@@ -9,18 +9,18 @@ test_description="Test HTTP Gateway (Writable)"
.
lib/test-lib.sh
.
lib/test-lib.sh
test_init_ipfs
test_init_ipfs
test_config_ipfs_gateway_writable
$ADDR_GWAY
test_config_ipfs_gateway_writable
test_launch_ipfs_daemon
test_launch_ipfs_daemon
port
=
$
PORT_GWAY
port
=
$
GWAY_PORT
test_expect_success
"ipfs daemon up"
'
test_expect_success
"ipfs daemon up"
'
pollEndpoint -host $
ADDR_GWAY
-ep=/version -v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||
pollEndpoint -host $
GWAY_MADDR
-ep=/version -v -tout=1s -tries=60 2>poll_apierr > poll_apiout ||
test_fsh cat poll_apierr || test_fsh cat poll_apiout
test_fsh cat poll_apierr || test_fsh cat poll_apiout
'
'
test_expect_success
"HTTP gateway gives access to sample file"
'
test_expect_success
"HTTP gateway gives access to sample file"
'
curl -s -o welcome "http://
localhost:$PORT_GWAY
/ipfs/$HASH_WELCOME_DOCS/readme" &&
curl -s -o welcome "http://
$GWAY_ADDR
/ipfs/$HASH_WELCOME_DOCS/readme" &&
grep "Hello and Welcome to IPFS!" welcome
grep "Hello and Welcome to IPFS!" welcome
'
'
...
...
test/sharness/t0112-gateway-cors.sh
浏览文件 @
0c7595b6
...
@@ -19,12 +19,11 @@ test_config_ipfs_cors_headers() {
...
@@ -19,12 +19,11 @@ test_config_ipfs_cors_headers() {
.
lib/test-lib.sh
.
lib/test-lib.sh
test_init_ipfs
test_init_ipfs
test_config_ipfs_gateway_readonly
$ADDR_GWAY
test_config_ipfs_cors_headers
test_config_ipfs_cors_headers
test_launch_ipfs_daemon
test_launch_ipfs_daemon
gwport
=
$
PORT_GWAY
gwport
=
$
GWAY_PORT
apiport
=
$
PORT_API
apiport
=
$
API_PORT
thash
=
'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
thash
=
'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
# Gateway
# Gateway
...
...
test/sharness/t0121-bootstrap-iptb.sh
浏览文件 @
0c7595b6
...
@@ -58,7 +58,7 @@ test_expect_success "reset iptb nodes" '
...
@@ -58,7 +58,7 @@ test_expect_success "reset iptb nodes" '
test_expect_success
"set bootstrap addrs"
'
test_expect_success
"set bootstrap addrs"
'
bsn_peer_id=$(ipfs id -f "<id>") &&
bsn_peer_id=$(ipfs id -f "<id>") &&
BADDR="/ip4/127.0.0.1/tcp/$
PORT_SWARM
/ipfs/$bsn_peer_id" &&
BADDR="/ip4/127.0.0.1/tcp/$
SWARM_PORT
/ipfs/$bsn_peer_id" &&
ipfsi 0 bootstrap add $BADDR &&
ipfsi 0 bootstrap add $BADDR &&
ipfsi 1 bootstrap add $BADDR &&
ipfsi 1 bootstrap add $BADDR &&
ipfsi 2 bootstrap add $BADDR &&
ipfsi 2 bootstrap add $BADDR &&
...
...
test/sharness/t0230-channel-streaming-http-content-type.sh
浏览文件 @
0c7595b6
...
@@ -16,7 +16,7 @@ test_ls_cmd() {
...
@@ -16,7 +16,7 @@ test_ls_cmd() {
mkdir -p testdir &&
mkdir -p testdir &&
echo "hello test" >testdir/test.txt &&
echo "hello test" >testdir/test.txt &&
ipfs add -r testdir &&
ipfs add -r testdir &&
curl -i "http://
localhost:$PORT_API
/api/v0/refs?arg=QmTcJAn3JP8ZMAKS6WS75q8sbTyojWKbxcUHgLYGWur4Ym&stream-channels=true&encoding=text" >actual_output
curl -i "http://
$API_ADDR
/api/v0/refs?arg=QmTcJAn3JP8ZMAKS6WS75q8sbTyojWKbxcUHgLYGWur4Ym&stream-channels=true&encoding=text" >actual_output
'
'
test_expect_success
"Text encoded channel-streaming command output looks good"
'
test_expect_success
"Text encoded channel-streaming command output looks good"
'
...
@@ -39,7 +39,7 @@ test_ls_cmd() {
...
@@ -39,7 +39,7 @@ test_ls_cmd() {
mkdir -p testdir &&
mkdir -p testdir &&
echo "hello test" >testdir/test.txt &&
echo "hello test" >testdir/test.txt &&
ipfs add -r testdir &&
ipfs add -r testdir &&
curl -i "http://
localhost:$PORT_API
/api/v0/refs?arg=QmTcJAn3JP8ZMAKS6WS75q8sbTyojWKbxcUHgLYGWur4Ym&stream-channels=true&encoding=json" >actual_output
curl -i "http://
$API_ADDR
/api/v0/refs?arg=QmTcJAn3JP8ZMAKS6WS75q8sbTyojWKbxcUHgLYGWur4Ym&stream-channels=true&encoding=json" >actual_output
'
'
test_expect_success
"JSON encoded channel-streaming command output looks good"
'
test_expect_success
"JSON encoded channel-streaming command output looks good"
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论