Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
bb6bf4ce
提交
bb6bf4ce
authored
1月 08, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: block tests
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
b125c89a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
174 行增加
和
2 行删除
+174
-2
block.go
core/coreapi/block.go
+7
-2
block_test.go
core/coreapi/block_test.go
+167
-0
没有找到文件。
core/coreapi/block.go
浏览文件 @
bb6bf4ce
...
...
@@ -12,6 +12,7 @@ import (
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
caopts
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
mh
"gx/ipfs/QmYeKnKpubCMRiq3PGZcTREErthbb5Q9cXsCoSkD9bjEBd/go-multihash"
blocks
"gx/ipfs/QmYsEQydGrsxNZfAiskvQ76N2xE9hDQtSAkRSynwMiUK3c/go-block-format"
cid
"gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
)
...
...
@@ -44,7 +45,7 @@ func (api *BlockAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Bloc
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unrecognized format: %s"
,
settings
.
Codec
)
}
if
settings
.
Codec
==
"v0"
{
if
settings
.
Codec
==
"v0"
&&
settings
.
MhType
==
mh
.
SHA2_256
{
pref
.
Version
=
0
}
pref
.
Codec
=
formatval
...
...
@@ -93,7 +94,11 @@ func (api *BlockAPI) Rm(ctx context.Context, p coreiface.Path, opts ...caopts.Bl
}
select
{
case
res
:=
<-
out
:
case
res
,
ok
:=
<-
out
:
if
!
ok
{
return
nil
}
remBlock
,
ok
:=
res
.
(
*
util
.
RemovedBlock
)
if
!
ok
{
return
errors
.
New
(
"got unexpected output from util.RmBlocks"
)
...
...
core/coreapi/block_test.go
0 → 100644
浏览文件 @
bb6bf4ce
package
coreapi_test
import
(
"context"
"io/ioutil"
"strings"
"testing"
mh
"gx/ipfs/QmYeKnKpubCMRiq3PGZcTREErthbb5Q9cXsCoSkD9bjEBd/go-multihash"
)
func
TestBlockPut
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
res
.
Cid
()
.
String
()
!=
"QmPyo15ynbVrSTVdJL9th7JysHaAbXt9dM9tXk1bMHbRtk"
{
t
.
Errorf
(
"got wrong cid: %s"
,
res
.
Cid
()
.
String
())
}
}
func
TestBlockPutFormat
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
),
api
.
Block
()
.
WithFormat
(
"cbor"
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
res
.
Cid
()
.
String
()
!=
"zdpuAn4amuLWo8Widi5v6VQpuo2dnpnwbVE3oB6qqs7mDSeoa"
{
t
.
Errorf
(
"got wrong cid: %s"
,
res
.
Cid
()
.
String
())
}
}
func
TestBlockPutHash
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
),
api
.
Block
()
.
WithHash
(
mh
.
KECCAK_512
,
-
1
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
res
.
Cid
()
.
String
()
!=
"zBurKB9YZkcDf6xa53WBE8CFX4ydVqAyf9KPXBFZt5stJzEstaS8Hukkhu4gwpMtc1xHNDbzP7sPtQKyWsP3C8fbhkmrZ"
{
t
.
Errorf
(
"got wrong cid: %s"
,
res
.
Cid
()
.
String
())
}
}
func
TestBlockGet
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
),
api
.
Block
()
.
WithHash
(
mh
.
KECCAK_512
,
-
1
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
r
,
err
:=
api
.
Block
()
.
Get
(
ctx
,
res
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
d
,
err
:=
ioutil
.
ReadAll
(
r
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
string
(
d
)
!=
"Hello"
{
t
.
Error
(
"didn't get correct data back"
)
}
}
func
TestBlockRm
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
r
,
err
:=
api
.
Block
()
.
Get
(
ctx
,
res
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
d
,
err
:=
ioutil
.
ReadAll
(
r
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
string
(
d
)
!=
"Hello"
{
t
.
Error
(
"didn't get correct data back"
)
}
err
=
api
.
Block
()
.
Rm
(
ctx
,
res
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
_
,
err
=
api
.
Block
()
.
Get
(
ctx
,
res
)
if
err
==
nil
{
t
.
Error
(
"expected err to exist"
)
}
if
err
.
Error
()
!=
"blockservice: key not found"
{
t
.
Errorf
(
"unexpected error; %s"
,
err
.
Error
())
}
err
=
api
.
Block
()
.
Rm
(
ctx
,
res
)
if
err
==
nil
{
t
.
Error
(
"expected err to exist"
)
}
if
err
.
Error
()
!=
"blockstore: block not found"
{
t
.
Errorf
(
"unexpected error; %s"
,
err
.
Error
())
}
err
=
api
.
Block
()
.
Rm
(
ctx
,
res
,
api
.
Block
()
.
WithForce
(
true
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
}
func
TestBlockStat
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
stat
,
err
:=
api
.
Block
()
.
Stat
(
ctx
,
res
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
stat
.
Path
()
.
String
()
!=
res
.
String
()
{
t
.
Error
(
"paths don't match"
)
}
if
stat
.
Size
()
!=
len
(
"Hello"
)
{
t
.
Error
(
"length doesn't match"
)
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论