Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
96334bb0
Unverified
提交
96334bb0
authored
10月 26, 2018
作者:
Steven Allen
提交者:
GitHub
10月 26, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5660 from ipfs/fix/resolve-paths
namesys: properly attach path in name.Resolve
上级
223a0606
f4e5625b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
146 行增加
和
30 行删除
+146
-30
name_test.go
core/coreapi/name_test.go
+136
-29
namesys.go
namesys/namesys.go
+10
-1
没有找到文件。
core/coreapi/name_test.go
浏览文件 @
96334bb0
...
...
@@ -2,9 +2,11 @@ package coreapi_test
import
(
"context"
"github.com/ipfs/go-ipfs/core"
"io"
"io/ioutil"
"math/rand"
"path"
"testing"
"time"
...
...
@@ -21,45 +23,150 @@ func addTestObject(ctx context.Context, api coreiface.CoreAPI) (coreiface.Path,
return
api
.
Unixfs
()
.
Add
(
ctx
,
files
.
NewReaderFile
(
""
,
""
,
ioutil
.
NopCloser
(
&
io
.
LimitedReader
{
R
:
rnd
,
N
:
4092
}),
nil
))
}
func
TestBasicPublishResolve
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
nds
,
apis
,
err
:=
makeAPISwarm
(
ctx
,
true
,
5
)
func
appendPath
(
p
coreiface
.
Path
,
sub
string
)
coreiface
.
Path
{
p
,
err
:=
coreiface
.
ParsePath
(
path
.
Join
(
p
.
String
(),
sub
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
panic
(
err
)
}
n
:=
nds
[
0
]
api
:=
apis
[
0
]
return
p
}
p
,
err
:=
addTestObject
(
ctx
,
api
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
func
TestPublishResolve
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
init
:=
func
()
(
*
core
.
IpfsNode
,
coreiface
.
CoreAPI
,
coreiface
.
Path
)
{
nds
,
apis
,
err
:=
makeAPISwarm
(
ctx
,
true
,
5
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
nil
,
nil
,
nil
}
n
:=
nds
[
0
]
api
:=
apis
[
0
]
e
,
err
:=
api
.
Name
()
.
Publish
(
ctx
,
p
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
p
,
err
:=
addTestObject
(
ctx
,
api
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
nil
,
nil
,
nil
}
return
n
,
api
,
p
}
if
e
.
Name
()
!=
n
.
Identity
.
Pretty
()
{
t
.
Errorf
(
"expected e.Name to equal '%s', got '%s'"
,
n
.
Identity
.
Pretty
(),
e
.
Name
())
}
run
:=
func
(
t
*
testing
.
T
,
ropts
[]
opt
.
NameResolveOption
)
{
t
.
Run
(
"basic"
,
func
(
t
*
testing
.
T
)
{
n
,
api
,
p
:=
init
()
e
,
err
:=
api
.
Name
()
.
Publish
(
ctx
,
p
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
e
.
Value
()
.
String
()
!=
p
.
String
()
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
e
.
Value
()
.
String
(),
p
.
String
())
}
if
e
.
Name
()
!=
n
.
Identity
.
Pretty
()
{
t
.
Errorf
(
"expected e.Name to equal '%s', got '%s'"
,
n
.
Identity
.
Pretty
(),
e
.
Name
())
}
resPath
,
err
:=
api
.
Name
()
.
Resolve
(
ctx
,
e
.
Name
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
e
.
Value
()
.
String
()
!=
p
.
String
()
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
e
.
Value
()
.
String
(),
p
.
String
())
}
if
resPath
.
String
()
!=
p
.
String
()
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
resPath
.
String
(),
p
.
String
())
resPath
,
err
:=
api
.
Name
()
.
Resolve
(
ctx
,
e
.
Name
(),
ropts
...
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
resPath
.
String
()
!=
p
.
String
()
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
resPath
.
String
(),
p
.
String
())
}
})
t
.
Run
(
"publishPath"
,
func
(
t
*
testing
.
T
)
{
n
,
api
,
p
:=
init
()
e
,
err
:=
api
.
Name
()
.
Publish
(
ctx
,
appendPath
(
p
,
"/test"
))
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
()
+
"/test"
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
e
.
Value
()
.
String
(),
p
.
String
())
}
resPath
,
err
:=
api
.
Name
()
.
Resolve
(
ctx
,
e
.
Name
(),
ropts
...
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
resPath
.
String
()
!=
p
.
String
()
+
"/test"
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
resPath
.
String
(),
p
.
String
()
+
"/test"
)
}
})
t
.
Run
(
"revolvePath"
,
func
(
t
*
testing
.
T
)
{
n
,
api
,
p
:=
init
()
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
()
+
"/test"
,
ropts
...
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
resPath
.
String
()
!=
p
.
String
()
+
"/test"
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
resPath
.
String
(),
p
.
String
()
+
"/test"
)
}
})
t
.
Run
(
"publishRevolvePath"
,
func
(
t
*
testing
.
T
)
{
n
,
api
,
p
:=
init
()
e
,
err
:=
api
.
Name
()
.
Publish
(
ctx
,
appendPath
(
p
,
"/a"
))
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
()
+
"/a"
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
e
.
Value
()
.
String
(),
p
.
String
())
}
resPath
,
err
:=
api
.
Name
()
.
Resolve
(
ctx
,
e
.
Name
()
+
"/b"
,
ropts
...
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
return
}
if
resPath
.
String
()
!=
p
.
String
()
+
"/a/b"
{
t
.
Errorf
(
"expected paths to match, '%s'!='%s'"
,
resPath
.
String
(),
p
.
String
()
+
"/a/b"
)
}
})
}
t
.
Run
(
"default"
,
func
(
t
*
testing
.
T
)
{
run
(
t
,
[]
opt
.
NameResolveOption
{})
})
t
.
Run
(
"nocache"
,
func
(
t
*
testing
.
T
)
{
run
(
t
,
[]
opt
.
NameResolveOption
{
opt
.
Name
.
Cache
(
false
)})
})
}
func
TestBasicPublishResolveKey
(
t
*
testing
.
T
)
{
...
...
namesys/namesys.go
浏览文件 @
96334bb0
...
...
@@ -100,6 +100,14 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.
key
:=
segments
[
2
]
if
p
,
ok
:=
ns
.
cacheGet
(
key
);
ok
{
if
len
(
segments
)
>
3
{
var
err
error
p
,
err
=
path
.
FromSegments
(
""
,
strings
.
TrimRight
(
p
.
String
(),
"/"
),
segments
[
3
])
if
err
!=
nil
{
emitOnceResult
(
ctx
,
out
,
onceResult
{
value
:
p
,
err
:
err
})
}
}
out
<-
onceResult
{
value
:
p
}
close
(
out
)
return
out
...
...
@@ -139,7 +147,8 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.
// Attach rest of the path
if
len
(
segments
)
>
3
{
p
,
err
:=
path
.
FromSegments
(
""
,
strings
.
TrimRight
(
p
.
String
(),
"/"
),
segments
[
3
])
var
err
error
p
,
err
=
path
.
FromSegments
(
""
,
strings
.
TrimRight
(
p
.
String
(),
"/"
),
segments
[
3
])
if
err
!=
nil
{
emitOnceResult
(
ctx
,
out
,
onceResult
{
value
:
p
,
ttl
:
res
.
ttl
,
err
:
err
})
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论