Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
bc49bee6
Commit
bc49bee6
authored
Jan 16, 2016
by
Stephen Whitmore
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implements path.IsJustAKey().
License: MIT Signed-off-by:
Stephen Whitmore
<
noffle@ipfs.io
>
parent
c242660d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
path/path.go
path/path.go
+6
-0
path/path_test.go
path/path_test.go
+20
-0
No files found.
path/path.go
View file @
bc49bee6
...
...
@@ -44,6 +44,12 @@ func (p Path) String() string {
return
string
(
p
)
}
// IsJustAKey returns true if the path is of the form <key> or /ipfs/<key>.
func
(
p
Path
)
IsJustAKey
()
bool
{
parts
:=
p
.
Segments
()
return
(
len
(
parts
)
==
2
&&
parts
[
0
]
==
"ipfs"
)
}
func
FromSegments
(
prefix
string
,
seg
...
string
)
(
Path
,
error
)
{
return
ParsePath
(
prefix
+
strings
.
Join
(
seg
,
"/"
))
}
...
...
path/path_test.go
View file @
bc49bee6
...
...
@@ -28,3 +28,23 @@ func TestPathParsing(t *testing.T) {
}
}
}
func
TestIsJustAKey
(
t
*
testing
.
T
)
{
cases
:=
map
[
string
]
bool
{
"QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
:
true
,
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
:
true
,
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a"
:
false
,
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b"
:
false
,
}
for
p
,
expected
:=
range
cases
{
path
,
err
:=
ParsePath
(
p
)
if
err
!=
nil
{
t
.
Fatalf
(
"ParsePath failed to parse
\"
%s
\"
, but should have succeeded"
,
p
)
}
result
:=
path
.
IsJustAKey
()
if
result
!=
expected
{
t
.
Fatalf
(
"expected IsJustAKey(%s) to return %v, not %v"
,
p
,
expected
,
result
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment