Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
d9961893
提交
d9961893
authored
12月 22, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
net/id_test: refactor tests into own func
上级
c2b21e47
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
39 行增加
和
38 行删除
+39
-38
id_test.go
net/id_test.go
+39
-38
没有找到文件。
net/id_test.go
浏览文件 @
d9961893
...
...
@@ -39,60 +39,61 @@ func TestIDService(t *testing.T) {
n1
:=
GenNetwork
(
t
,
ctx
)
n2
:=
GenNetwork
(
t
,
ctx
)
testKnowsAddrs
:=
func
(
n
inet
.
Network
,
p
peer
.
ID
,
expected
[]
ma
.
Multiaddr
)
{
actual
:=
n
.
Peerstore
()
.
Addresses
(
p
)
if
len
(
actual
)
!=
len
(
expected
)
{
t
.
Error
(
"dont have the same addresses"
)
}
have
:=
map
[
string
]
struct
{}{}
for
_
,
addr
:=
range
actual
{
have
[
addr
.
String
()]
=
struct
{}{}
}
for
_
,
addr
:=
range
expected
{
if
_
,
found
:=
have
[
addr
.
String
()];
!
found
{
t
.
Errorf
(
"%s did not have addr for %s: %s"
,
n
.
LocalPeer
(),
p
,
addr
)
panic
(
"ahhhhhhh"
)
}
}
}
testHasProtocolVersions
:=
func
(
n
inet
.
Network
,
p
peer
.
ID
)
{
v
,
err
:=
n
.
Peerstore
()
.
Get
(
p
,
"ProtocolVersion"
)
if
v
.
(
string
)
!=
handshake
.
IpfsVersion
.
String
()
{
t
.
Fatal
(
"protocol mismatch"
,
err
)
}
v
,
err
=
n
.
Peerstore
()
.
Get
(
p
,
"AgentVersion"
)
if
v
.
(
string
)
!=
handshake
.
ClientVersion
{
t
.
Fatal
(
"agent version mismatch"
,
err
)
}
}
n1p
:=
n1
.
LocalPeer
()
n2p
:=
n2
.
LocalPeer
()
testKnowsAddrs
(
n1
,
n2p
,
[]
ma
.
Multiaddr
{})
// nothing
testKnowsAddrs
(
n2
,
n1p
,
[]
ma
.
Multiaddr
{})
// nothing
testKnowsAddrs
(
t
,
n1
,
n2p
,
[]
ma
.
Multiaddr
{})
// nothing
testKnowsAddrs
(
t
,
n2
,
n1p
,
[]
ma
.
Multiaddr
{})
// nothing
// have n2 tell n1, so we can dial...
DivulgeAddresses
(
n2
,
n1
)
testKnowsAddrs
(
n1
,
n2p
,
n2
.
Peerstore
()
.
Addresses
(
n2p
))
// has them
testKnowsAddrs
(
n2
,
n1p
,
[]
ma
.
Multiaddr
{})
// nothing
testKnowsAddrs
(
t
,
n1
,
n2p
,
n2
.
Peerstore
()
.
Addresses
(
n2p
))
// has them
testKnowsAddrs
(
t
,
n2
,
n1p
,
[]
ma
.
Multiaddr
{})
// nothing
if
err
:=
n1
.
DialPeer
(
ctx
,
n2p
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to dial:"
,
err
)
}
// this is shitty. dial should wait for connecting to end
<-
time
.
After
(
100
*
time
.
Millisecond
)
// the IDService should be opened automatically, by the network.
// what we should see now is that both peers know about each others listen addresses.
testKnowsAddrs
(
n1
,
n2p
,
n2
.
Peerstore
()
.
Addresses
(
n2p
))
// has them
testKnowsAddrs
(
n2
,
n1p
,
n1
.
Peerstore
()
.
Addresses
(
n1p
))
// has them
testKnowsAddrs
(
t
,
n1
,
n2p
,
n2
.
Peerstore
()
.
Addresses
(
n2p
))
// has them
testKnowsAddrs
(
t
,
n2
,
n1p
,
n1
.
Peerstore
()
.
Addresses
(
n1p
))
// has them
// and the protocol versions.
testHasProtocolVersions
(
n1
,
n2p
)
testHasProtocolVersions
(
n2
,
n1p
)
testHasProtocolVersions
(
t
,
n1
,
n2p
)
testHasProtocolVersions
(
t
,
n2
,
n1p
)
}
func
testKnowsAddrs
(
t
*
testing
.
T
,
n
inet
.
Network
,
p
peer
.
ID
,
expected
[]
ma
.
Multiaddr
)
{
actual
:=
n
.
Peerstore
()
.
Addresses
(
p
)
if
len
(
actual
)
!=
len
(
expected
)
{
t
.
Error
(
"dont have the same addresses"
)
}
have
:=
map
[
string
]
struct
{}{}
for
_
,
addr
:=
range
actual
{
have
[
addr
.
String
()]
=
struct
{}{}
}
for
_
,
addr
:=
range
expected
{
if
_
,
found
:=
have
[
addr
.
String
()];
!
found
{
t
.
Errorf
(
"%s did not have addr for %s: %s"
,
n
.
LocalPeer
(),
p
,
addr
)
panic
(
"ahhhhhhh"
)
}
}
}
func
testHasProtocolVersions
(
t
*
testing
.
T
,
n
inet
.
Network
,
p
peer
.
ID
)
{
v
,
err
:=
n
.
Peerstore
()
.
Get
(
p
,
"ProtocolVersion"
)
if
v
.
(
string
)
!=
handshake
.
IpfsVersion
.
String
()
{
t
.
Fatal
(
"protocol mismatch"
,
err
)
}
v
,
err
=
n
.
Peerstore
()
.
Get
(
p
,
"AgentVersion"
)
if
v
.
(
string
)
!=
handshake
.
ClientVersion
{
t
.
Fatal
(
"agent version mismatch"
,
err
)
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论