Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
2109cbc1
提交
2109cbc1
authored
1月 02, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: Name tests
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
396c34b4
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
185 行增加
和
7 行删除
+185
-7
interface.go
core/coreapi/interface/interface.go
+4
-1
name_test.go
core/coreapi/name_test.go
+144
-0
unixfs_test.go
core/coreapi/unixfs_test.go
+37
-6
没有找到文件。
core/coreapi/interface/interface.go
浏览文件 @
2109cbc1
...
...
@@ -157,7 +157,10 @@ type KeyAPI interface {
WithType
(
algorithm
string
)
options
.
KeyGenerateOption
// WithSize is an option for Generate which specifies the size of the key to
// generated. Default is 0
// generated. Default is -1
//
// value of -1 means 'use default size for key type':
// * 2048 for RSA
WithSize
(
size
int
)
options
.
KeyGenerateOption
// Rename renames oldName key to newName. Returns the key and whether another
...
...
core/coreapi/name_test.go
0 → 100644
浏览文件 @
2109cbc1
package
coreapi_test
import
(
"context"
"io"
"math/rand"
"testing"
"time"
ipath
"github.com/ipfs/go-ipfs/path"
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
)
var
rnd
=
rand
.
New
(
rand
.
NewSource
(
0x62796532303137
))
func
addTestObject
(
ctx
context
.
Context
,
api
coreiface
.
CoreAPI
)
(
coreiface
.
Path
,
error
)
{
return
api
.
Unixfs
()
.
Add
(
ctx
,
&
io
.
LimitedReader
{
R
:
rnd
,
N
:
4092
})
}
func
TestBasicPublishResolve
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
n
,
api
,
err
:=
makeAPIIdent
(
ctx
,
true
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
p
,
err
:=
addTestObject
(
ctx
,
api
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
e
,
err
:=
api
.
Name
()
.
Publish
(
ctx
,
p
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
e
.
Name
()
!=
n
.
Identity
.
Pretty
()
{
t
.
Errorf
(
"expected e.Name to equal '%s', got '%s'"
,
n
.
Identity
.
Pretty
(),
e
.
Name
())
}
if
e
.
Value
()
.
String
()
!=
p
.
String
()
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
e
.
Value
()
.
String
(),
p
.
String
())
}
resPath
,
err
:=
api
.
Name
()
.
Resolve
(
ctx
,
e
.
Name
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
resPath
.
String
()
!=
p
.
String
()
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
resPath
.
String
(),
p
.
String
())
}
}
func
TestBasicPublishResolveKey
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPIIdent
(
ctx
,
true
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
k
,
err
:=
api
.
Key
()
.
Generate
(
ctx
,
"foo"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
p
,
err
:=
addTestObject
(
ctx
,
api
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
e
,
err
:=
api
.
Name
()
.
Publish
(
ctx
,
p
,
api
.
Name
()
.
WithKey
(
k
.
Name
()))
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
ipath
.
Join
([]
string
{
"/ipns"
,
e
.
Name
()})
!=
k
.
Path
()
.
String
()
{
t
.
Errorf
(
"expected e.Name to equal '%s', got '%s'"
,
e
.
Name
(),
k
.
Path
()
.
String
())
}
if
e
.
Value
()
.
String
()
!=
p
.
String
()
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
e
.
Value
()
.
String
(),
p
.
String
())
}
resPath
,
err
:=
api
.
Name
()
.
Resolve
(
ctx
,
e
.
Name
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
resPath
.
String
()
!=
p
.
String
()
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
resPath
.
String
(),
p
.
String
())
}
}
func
TestBasicPublishResolveTimeout
(
t
*
testing
.
T
)
{
t
.
Skip
(
"ValidTime doesn't appear to work at this time resolution"
)
ctx
:=
context
.
Background
()
n
,
api
,
err
:=
makeAPIIdent
(
ctx
,
true
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
p
,
err
:=
addTestObject
(
ctx
,
api
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
e
,
err
:=
api
.
Name
()
.
Publish
(
ctx
,
p
,
api
.
Name
()
.
WithValidTime
(
time
.
Millisecond
*
100
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
e
.
Name
()
!=
n
.
Identity
.
Pretty
()
{
t
.
Errorf
(
"expected e.Name to equal '%s', got '%s'"
,
n
.
Identity
.
Pretty
(),
e
.
Name
())
}
if
e
.
Value
()
.
String
()
!=
p
.
String
()
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
e
.
Value
()
.
String
(),
p
.
String
())
}
time
.
Sleep
(
time
.
Second
)
_
,
err
=
api
.
Name
()
.
Resolve
(
ctx
,
e
.
Name
())
if
err
==
nil
{
t
.
Fatal
(
"Expected an error"
)
return
}
}
//TODO: When swarm api is created, add multinode tests
core/coreapi/unixfs_test.go
浏览文件 @
2109cbc1
...
...
@@ -3,6 +3,7 @@ package coreapi_test
import
(
"bytes"
"context"
"encoding/base64"
"io"
"math"
"strings"
...
...
@@ -12,15 +13,16 @@ import (
coreapi
"github.com/ipfs/go-ipfs/core/coreapi"
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
coreunix
"github.com/ipfs/go-ipfs/core/coreunix"
keystore
"github.com/ipfs/go-ipfs/keystore"
mdag
"github.com/ipfs/go-ipfs/merkledag"
repo
"github.com/ipfs/go-ipfs/repo"
config
"github.com/ipfs/go-ipfs/repo/config"
ds2
"github.com/ipfs/go-ipfs/thirdparty/datastore2"
unixfs
"github.com/ipfs/go-ipfs/unixfs"
peer
"gx/ipfs/QmWNY7dV54ZDYmTA1ykVdwNCqC11mpU4zSUp6XDpLTH9eG/go-libp2p-peer"
ci
"gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
cbor
"gx/ipfs/QmeZv9VXw2SfVbX55LV6kGTWASKBc9ZxAVqGBeJcDGdoXy/go-ipld-cbor"
"github.com/ipfs/go-ipfs/keystore"
)
// `echo -n 'hello, world!' | ipfs add`
...
...
@@ -33,12 +35,37 @@ var emptyDir = coreapi.ResolvedPath("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbs
// `echo -n | ipfs add`
var
emptyFile
=
coreapi
.
ResolvedPath
(
"/ipfs/QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH"
,
nil
,
nil
)
func
makeAPI
(
ctx
context
.
Context
)
(
*
core
.
IpfsNode
,
coreiface
.
CoreAPI
,
error
)
{
func
makeAPIIdent
(
ctx
context
.
Context
,
fullIdentity
bool
)
(
*
core
.
IpfsNode
,
coreiface
.
CoreAPI
,
error
)
{
var
ident
config
.
Identity
if
fullIdentity
{
sk
,
pk
,
err
:=
ci
.
GenerateKeyPair
(
ci
.
RSA
,
512
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
id
,
err
:=
peer
.
IDFromPublicKey
(
pk
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
kbytes
,
err
:=
sk
.
Bytes
()
if
err
!=
nil
{
return
nil
,
nil
,
err
}
ident
=
config
.
Identity
{
PeerID
:
id
.
Pretty
(),
PrivKey
:
base64
.
StdEncoding
.
EncodeToString
(
kbytes
),
}
}
else
{
ident
=
config
.
Identity
{
PeerID
:
"Qmfoo"
,
}
}
r
:=
&
repo
.
Mock
{
C
:
config
.
Config
{
Identity
:
config
.
Identity
{
PeerID
:
"Qmfoo"
,
// required by offline node
},
Identity
:
ident
,
},
D
:
ds2
.
ThreadSafeCloserMapDatastore
(),
K
:
keystore
.
NewMemKeystore
(),
...
...
@@ -51,6 +78,10 @@ func makeAPI(ctx context.Context) (*core.IpfsNode, coreiface.CoreAPI, error) {
return
node
,
api
,
nil
}
func
makeAPI
(
ctx
context
.
Context
)
(
*
core
.
IpfsNode
,
coreiface
.
CoreAPI
,
error
)
{
return
makeAPIIdent
(
ctx
,
false
)
}
func
TestAdd
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
_
,
api
,
err
:=
makeAPI
(
ctx
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论