Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
d3f3afa5
提交
d3f3afa5
authored
9月 11, 2018
作者:
Łukasz Magiera
提交者:
Steven Allen
10月 05, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi pubsub: add tests
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
51bb9d68
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
100 行增加
和
1 行删除
+100
-1
pubsub.go
core/coreapi/interface/options/pubsub.go
+1
-1
pubsub_test.go
core/coreapi/pubsub_test.go
+96
-0
unixfs_test.go
core/coreapi/unixfs_test.go
+3
-0
没有找到文件。
core/coreapi/interface/options/pubsub.go
浏览文件 @
d3f3afa5
...
...
@@ -41,7 +41,7 @@ func PubSubSubscribeOptions(opts ...PubSubSubscribeOption) (*PubSubSubscribeSett
type
pubsubOpts
struct
{}
var
Pub
Bub
name
Opts
var
Pub
Sub
pubsub
Opts
func
(
pubsubOpts
)
Topic
(
topic
string
)
PubSubPeersOption
{
return
func
(
settings
*
PubSubPeersSettings
)
error
{
...
...
core/coreapi/pubsub_test.go
0 → 100644
浏览文件 @
d3f3afa5
package
coreapi_test
import
(
"context"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
"testing"
"time"
)
func
TestBasicPubSub
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
nds
,
apis
,
err
:=
makeAPISwarm
(
ctx
,
true
,
2
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
sub
,
err
:=
apis
[
0
]
.
PubSub
()
.
Subscribe
(
ctx
,
"testch"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
go
func
()
{
tick
:=
time
.
Tick
(
100
*
time
.
Millisecond
)
for
{
err
=
apis
[
1
]
.
PubSub
()
.
Publish
(
ctx
,
"testch"
,
[]
byte
(
"hello world"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
select
{
case
<-
tick
:
case
<-
ctx
.
Done
()
:
return
}
}
}()
m
,
err
:=
sub
.
Next
(
ctx
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
string
(
m
.
Data
())
!=
"hello world"
{
t
.
Errorf
(
"got invalid data: %s"
,
string
(
m
.
Data
()))
}
if
m
.
From
()
!=
nds
[
1
]
.
Identity
{
t
.
Errorf
(
"m.From didn't match"
)
}
peers
,
err
:=
apis
[
1
]
.
PubSub
()
.
Peers
(
ctx
,
options
.
PubSub
.
Topic
(
"testch"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
peers
)
!=
1
{
t
.
Fatalf
(
"got incorrect number of peers: %d"
,
len
(
peers
))
}
if
peers
[
0
]
!=
nds
[
0
]
.
Identity
{
t
.
Errorf
(
"peer didn't match"
)
}
peers
,
err
=
apis
[
1
]
.
PubSub
()
.
Peers
(
ctx
,
options
.
PubSub
.
Topic
(
"nottestch"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
peers
)
!=
0
{
t
.
Fatalf
(
"got incorrect number of peers: %d"
,
len
(
peers
))
}
topics
,
err
:=
apis
[
0
]
.
PubSub
()
.
Ls
(
ctx
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
topics
)
!=
1
{
t
.
Fatalf
(
"got incorrect number of topics: %d"
,
len
(
peers
))
}
if
topics
[
0
]
!=
"testch"
{
t
.
Errorf
(
"topic didn't match"
)
}
topics
,
err
=
apis
[
1
]
.
PubSub
()
.
Ls
(
ctx
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
topics
)
!=
0
{
t
.
Fatalf
(
"got incorrect number of topics: %d"
,
len
(
peers
))
}
}
core/coreapi/unixfs_test.go
浏览文件 @
d3f3afa5
...
...
@@ -94,6 +94,9 @@ func makeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]*core.IpfsNo
Repo
:
r
,
Host
:
mock
.
MockHostOption
(
mn
),
Online
:
fullIdentity
,
ExtraOpts
:
map
[
string
]
bool
{
"pubsub"
:
true
,
},
})
if
err
!=
nil
{
return
nil
,
nil
,
err
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论