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-merkledag
Commits
738204f2
Commit
738204f2
authored
Aug 23, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve test coverage on merkledag package
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
07070300
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
1 deletion
+103
-1
merkledag_test.go
merkledag_test.go
+25
-0
node_test.go
node_test.go
+78
-1
No files found.
merkledag_test.go
View file @
738204f2
...
...
@@ -17,6 +17,7 @@ import (
imp
"github.com/ipfs/go-ipfs/importer"
chunk
"github.com/ipfs/go-ipfs/importer/chunk"
.
"github.com/ipfs/go-ipfs/merkledag"
mdpb
"github.com/ipfs/go-ipfs/merkledag/pb"
dstest
"github.com/ipfs/go-ipfs/merkledag/test"
uio
"github.com/ipfs/go-ipfs/unixfs/io"
u
"gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
...
...
@@ -354,3 +355,27 @@ func TestFetchFailure(t *testing.T) {
}
}
}
func
TestUnmarshalFailure
(
t
*
testing
.
T
)
{
badData
:=
[]
byte
(
"hello world"
)
_
,
err
:=
DecodeProtobuf
(
badData
)
if
err
==
nil
{
t
.
Fatal
(
"shouldnt succeed to parse this"
)
}
// now with a bad link
pbn
:=
&
mdpb
.
PBNode
{
Links
:
[]
*
mdpb
.
PBLink
{{
Hash
:
[]
byte
(
"not a multihash"
)}}}
badlink
,
err
:=
pbn
.
Marshal
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
_
,
err
=
DecodeProtobuf
(
badlink
)
if
err
==
nil
{
t
.
Fatal
(
"should have failed to parse node with bad link"
)
}
n
:=
&
Node
{}
n
.
Marshal
()
}
node_test.go
View file @
738204f2
package
merkledag
package
merkledag
_test
import
(
"testing"
.
"github.com/ipfs/go-ipfs/merkledag"
mdtest
"github.com/ipfs/go-ipfs/merkledag/test"
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
)
func
TestRemoveLink
(
t
*
testing
.
T
)
{
...
...
@@ -52,3 +57,75 @@ func TestRemoveLink(t *testing.T) {
t
.
Fatal
(
"link order wrong"
)
}
}
func
TestFindLink
(
t
*
testing
.
T
)
{
ds
:=
mdtest
.
Mock
()
k
,
err
:=
ds
.
Add
(
new
(
Node
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
nd
:=
&
Node
{
Links
:
[]
*
Link
{
&
Link
{
Name
:
"a"
,
Hash
:
k
.
ToMultihash
()},
&
Link
{
Name
:
"c"
,
Hash
:
k
.
ToMultihash
()},
&
Link
{
Name
:
"b"
,
Hash
:
k
.
ToMultihash
()},
},
}
_
,
err
=
ds
.
Add
(
nd
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
lnk
,
err
:=
nd
.
GetNodeLink
(
"b"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
lnk
.
Name
!=
"b"
{
t
.
Fatal
(
"got wrong link back"
)
}
_
,
err
=
nd
.
GetNodeLink
(
"f"
)
if
err
!=
ErrLinkNotFound
{
t
.
Fatal
(
"shouldnt have found link"
)
}
_
,
err
=
nd
.
GetLinkedNode
(
context
.
Background
(),
ds
,
"b"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
outnd
,
err
:=
nd
.
UpdateNodeLink
(
"b"
,
nd
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
olnk
,
err
:=
outnd
.
GetNodeLink
(
"b"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
olnk
.
Hash
.
B58String
()
==
k
.
B58String
()
{
t
.
Fatal
(
"new link should have different hash"
)
}
}
func
TestNodeCopy
(
t
*
testing
.
T
)
{
nd
:=
&
Node
{
Links
:
[]
*
Link
{
&
Link
{
Name
:
"a"
},
&
Link
{
Name
:
"c"
},
&
Link
{
Name
:
"b"
},
},
}
nd
.
SetData
([]
byte
(
"testing"
))
ond
:=
nd
.
Copy
()
ond
.
SetData
(
nil
)
if
nd
.
Data
()
==
nil
{
t
.
Fatal
(
"should be different objects"
)
}
}
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