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-ld-format
Commits
428368d2
Commit
428368d2
authored
Jul 11, 2017
by
Jakub Sztandera
Committed by
GitHub
Jul 11, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20 from Stebalien/add-tests
Add tests
parents
864b7f9d
f718bf7e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
132 additions
and
4 deletions
+132
-4
coding_test.go
coding_test.go
+50
-0
format_test.go
format_test.go
+72
-0
package.json
package.json
+10
-4
No files found.
coding_test.go
0 → 100644
View file @
428368d2
package
format
import
(
"errors"
"testing"
blocks
"github.com/ipfs/go-block-format"
cid
"github.com/ipfs/go-cid"
mh
"github.com/multiformats/go-multihash"
)
func
init
()
{
DefaultBlockDecoder
[
cid
.
Raw
]
=
func
(
b
blocks
.
Block
)
(
Node
,
error
)
{
node
:=
&
EmptyNode
{}
if
b
.
RawData
()
!=
nil
||
!
b
.
Cid
()
.
Equals
(
node
.
Cid
())
{
return
nil
,
errors
.
New
(
"can only decode empty blocks"
)
}
return
node
,
nil
}
}
func
TestDecode
(
t
*
testing
.
T
)
{
id
,
err
:=
cid
.
Prefix
{
Version
:
1
,
Codec
:
cid
.
Raw
,
MhType
:
mh
.
ID
,
MhLength
:
0
,
}
.
Sum
(
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create cid: %s"
,
err
)
}
block
,
err
:=
blocks
.
NewBlockWithCid
(
nil
,
id
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create empty block: %s"
,
err
)
}
node
,
err
:=
Decode
(
block
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to decode empty node: %s"
,
err
)
}
if
!
node
.
Cid
()
.
Equals
(
id
)
{
t
.
Fatalf
(
"empty node doesn't have the right cid"
)
}
if
_
,
ok
:=
node
.
(
*
EmptyNode
);
!
ok
{
t
.
Fatalf
(
"empty node doesn't have the right type"
)
}
}
format_test.go
0 → 100644
View file @
428368d2
package
format
import
(
"errors"
"testing"
cid
"github.com/ipfs/go-cid"
mh
"github.com/multiformats/go-multihash"
)
type
EmptyNode
struct
{}
var
EmptyNodeError
error
=
errors
.
New
(
"dummy node"
)
func
(
n
*
EmptyNode
)
Resolve
([]
string
)
(
interface
{},
[]
string
,
error
)
{
return
nil
,
nil
,
EmptyNodeError
}
func
(
n
*
EmptyNode
)
Tree
(
string
,
int
)
[]
string
{
return
nil
}
func
(
n
*
EmptyNode
)
ResolveLink
([]
string
)
(
*
Link
,
[]
string
,
error
)
{
return
nil
,
nil
,
EmptyNodeError
}
func
(
n
*
EmptyNode
)
Copy
()
Node
{
return
&
EmptyNode
{}
}
func
(
n
*
EmptyNode
)
Cid
()
*
cid
.
Cid
{
id
,
err
:=
cid
.
Prefix
{
Version
:
1
,
Codec
:
cid
.
Raw
,
MhType
:
mh
.
ID
,
MhLength
:
0
,
}
.
Sum
(
nil
)
if
err
!=
nil
{
panic
(
"failed to create an empty cid!"
)
}
return
id
}
func
(
n
*
EmptyNode
)
Links
()
[]
*
Link
{
return
nil
}
func
(
n
*
EmptyNode
)
Loggable
()
map
[
string
]
interface
{}
{
return
nil
}
func
(
n
*
EmptyNode
)
String
()
string
{
return
"[]"
}
func
(
n
*
EmptyNode
)
RawData
()
[]
byte
{
return
nil
}
func
(
n
*
EmptyNode
)
Size
()
(
uint64
,
error
)
{
return
0
,
nil
}
func
(
n
*
EmptyNode
)
Stat
()
(
*
NodeStat
,
error
)
{
return
&
NodeStat
{},
nil
}
func
TestNodeType
(
t
*
testing
.
T
)
{
// Type assertion.
var
_
Node
=
&
EmptyNode
{}
}
package.json
View file @
428368d2
...
...
@@ -9,15 +9,21 @@
"gxDependencies"
:
[
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
a4RJSuh7mMeJQYCqMbKzekn6EwBo7HEs5AQYjVRMQATB
"
,
"hash"
:
"Qm
TprEaAA2A9bst5XH7exuyi5KzNMK3SEDNN8rBDnKWcUS
"
,
"name"
:
"go-cid"
,
"version"
:
"0.7.1
6
"
"version"
:
"0.7.1
7
"
},
{
"author"
:
"stebalien"
,
"hash"
:
"Qm
XxGS5QsUxpR3iqL5DjmsYPHR1Yz74siRQ4ChJqWFosMh
"
,
"hash"
:
"Qm
VA4mafxbfH5aEvNz8fyoxC6J1xhAtw88B4GerPznSZBg
"
,
"name"
:
"go-block-format"
,
"version"
:
"0.1.2"
"version"
:
"0.1.3"
},
{
"author"
:
"multiformats"
,
"hash"
:
"QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P"
,
"name"
:
"go-multihash"
,
"version"
:
"1.0.5"
}
],
"gxVersion"
:
"0.10.0"
,
...
...
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