Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
548490f5
提交
548490f5
authored
12月 17, 2016
作者:
Jeromy Johnson
提交者:
GitHub
12月 17, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3516 from Zanadar/test/routing/offline
Test/routing/offline
上级
e2ba43c1
834f2232
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
88 行增加
和
0 行删除
+88
-0
offline_test.go
routing/offline/offline_test.go
+79
-0
gen.go
thirdparty/testutil/gen.go
+9
-0
没有找到文件。
routing/offline/offline_test.go
0 → 100644
浏览文件 @
548490f5
package
offline
import
(
"bytes"
"context"
"github.com/ipfs/go-ipfs/thirdparty/testutil"
ds
"gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
"testing"
)
func
TestOfflineRouterStorage
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
nds
:=
ds
.
NewMapDatastore
()
privkey
,
_
,
_
:=
testutil
.
RandTestKeyPair
(
128
)
offline
:=
NewOfflineRouter
(
nds
,
privkey
)
err
:=
offline
.
PutValue
(
ctx
,
"key"
,
[]
byte
(
"testing 1 2 3"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
val
,
err
:=
offline
.
GetValue
(
ctx
,
"key"
)
if
!
bytes
.
Equal
([]
byte
(
"testing 1 2 3"
),
val
)
{
t
.
Fatal
(
"OfflineRouter does not properly store"
)
}
val
,
err
=
offline
.
GetValue
(
ctx
,
"notHere"
)
if
err
==
nil
{
t
.
Fatal
(
"Router should throw errors for unfound records"
)
}
recVal
,
err
:=
offline
.
GetValues
(
ctx
,
"key"
,
0
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
_
,
err
=
offline
.
GetValues
(
ctx
,
"notHere"
,
0
)
if
err
==
nil
{
t
.
Fatal
(
"Router should throw errors for unfound records"
)
}
local
:=
recVal
[
0
]
.
Val
if
!
bytes
.
Equal
([]
byte
(
"testing 1 2 3"
),
local
)
{
t
.
Fatal
(
"OfflineRouter does not properly store"
)
}
}
func
TestOfflineRouterLocal
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
nds
:=
ds
.
NewMapDatastore
()
privkey
,
_
,
_
:=
testutil
.
RandTestKeyPair
(
128
)
offline
:=
NewOfflineRouter
(
nds
,
privkey
)
id
,
_
:=
testutil
.
RandPeerID
()
_
,
err
:=
offline
.
FindPeer
(
ctx
,
id
)
if
err
!=
ErrOffline
{
t
.
Fatal
(
"OfflineRouting should alert that its offline"
)
}
cid
,
_
:=
testutil
.
RandCidV0
()
pChan
:=
offline
.
FindProvidersAsync
(
ctx
,
cid
,
1
)
p
,
ok
:=
<-
pChan
if
ok
{
t
.
Fatalf
(
"FindProvidersAsync did not return a closed channel. Instead we got %+v !"
,
p
)
}
cid
,
_
=
testutil
.
RandCidV0
()
err
=
offline
.
Provide
(
ctx
,
cid
)
if
err
!=
ErrOffline
{
t
.
Fatal
(
"OfflineRouting should alert that its offline"
)
}
err
=
offline
.
Bootstrap
(
ctx
)
if
err
!=
nil
{
t
.
Fatal
(
"You shouldn't be able to bootstrap offline routing."
)
}
}
thirdparty/testutil/gen.go
浏览文件 @
548490f5
...
...
@@ -9,6 +9,7 @@ import (
"testing"
u
"gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
cid
"gx/ipfs/QmcTcsTvfaeEBRFo1TkFgT8sRmgi1n1LTZpecfVP8fzpGD/go-cid"
peer
"gx/ipfs/QmfMmLGoKzCHDN7cGgk64PJr4iipzidDRME8HABSJqvmhC/go-libp2p-peer"
ci
"gx/ipfs/QmfWDLQjGjVe4fr5CoztYW2DYYjRysMJrFe1RCsXLPTf46/go-libp2p-crypto"
...
...
@@ -50,6 +51,14 @@ func RandPeerID() (peer.ID, error) {
return
peer
.
ID
(
h
),
nil
}
func
RandCidV0
()
(
*
cid
.
Cid
,
error
)
{
buf
:=
make
([]
byte
,
16
)
if
_
,
err
:=
io
.
ReadFull
(
u
.
NewTimeSeededRand
(),
buf
);
err
!=
nil
{
return
&
cid
.
Cid
{},
err
}
return
cid
.
NewCidV0
(
buf
),
nil
}
func
RandPeerIDFatal
(
t
testing
.
TB
)
peer
.
ID
{
p
,
err
:=
RandPeerID
()
if
err
!=
nil
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论