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
interface-go-dms3-core
Commits
16127b29
Commit
16127b29
authored
Dec 02, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(tests): put valid blocks
parent
48dcedec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
13 deletions
+39
-13
tests/block.go
tests/block.go
+39
-13
No files found.
tests/block.go
View file @
16127b29
package
tests
import
(
"bytes"
"context"
"
github.com/ipfs/interface-go-ipfs-core/path
"
"
io
"
"io/ioutil"
"strings"
"testing"
coreiface
"github.com/ipfs/interface-go-ipfs-core"
opt
"github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/path"
mh
"github.com/multiformats/go-multihash"
)
var
(
pbCid
=
"QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN"
cborCid
=
"bafyreicnga62zhxnmnlt6ymq5hcbsg7gdhqdu6z4ehu3wpjhvqnflfy6nm"
cborKCid
=
"bafyr2qgsohbwdlk7ajmmbb4lhoytmest4wdbe5xnexfvtxeatuyqqmwv3fgxp3pmhpc27gwey2cct56gloqefoqwcf3yqiqzsaqb7p4jefhcw"
)
func
pbBlock
()
io
.
Reader
{
return
bytes
.
NewReader
([]
byte
{
10
,
12
,
8
,
2
,
18
,
6
,
104
,
101
,
108
,
108
,
111
,
10
,
24
,
6
})
}
func
cborBlock
()
io
.
Reader
{
return
bytes
.
NewReader
([]
byte
{
101
,
72
,
101
,
108
,
108
,
111
})
}
func
(
tp
*
TestSuite
)
TestBlock
(
t
*
testing
.
T
)
{
tp
.
hasApi
(
t
,
func
(
api
coreiface
.
CoreAPI
)
error
{
if
api
.
Block
()
==
nil
{
...
...
@@ -38,12 +54,12 @@ func (tp *TestSuite) TestBlockPut(t *testing.T) {
t
.
Fatal
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
))
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
pbBlock
(
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
res
.
Path
()
.
Cid
()
.
String
()
!=
"QmPyo15ynbVrSTVdJL9th7JysHaAbXt9dM9tXk1bMHbRtk"
{
if
res
.
Path
()
.
Cid
()
.
String
()
!=
pbCid
{
t
.
Errorf
(
"got wrong cid: %s"
,
res
.
Path
()
.
Cid
()
.
String
())
}
}
...
...
@@ -56,12 +72,12 @@ func (tp *TestSuite) TestBlockPutFormat(t *testing.T) {
t
.
Fatal
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
),
opt
.
Block
.
Format
(
"cbor"
))
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
cborBlock
(
),
opt
.
Block
.
Format
(
"cbor"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
res
.
Path
()
.
Cid
()
.
String
()
!=
"bafyreiayl6g3gitr7ys7kyng7sjywlrgimdoymco3jiyab6rozecmoazne"
{
if
res
.
Path
()
.
Cid
()
.
String
()
!=
cborCid
{
t
.
Errorf
(
"got wrong cid: %s"
,
res
.
Path
()
.
Cid
()
.
String
())
}
}
...
...
@@ -74,12 +90,17 @@ func (tp *TestSuite) TestBlockPutHash(t *testing.T) {
t
.
Fatal
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
),
opt
.
Block
.
Hash
(
mh
.
KECCAK_512
,
-
1
))
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
cborBlock
(),
opt
.
Block
.
Hash
(
mh
.
KECCAK_512
,
-
1
),
opt
.
Block
.
Format
(
"cbor"
),
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
res
.
Path
()
.
Cid
()
.
String
()
!=
"bafyb2qgdh7w6dcq24u65xbtdoehyavegnpvxcqce7ttvs6ielgmwdfxrahmu37d33atik57x5y6s7d7qz32aasuwgirh3ocn6ywswqdifvu6e"
{
if
res
.
Path
()
.
Cid
()
.
String
()
!=
cborKCid
{
t
.
Errorf
(
"got wrong cid: %s"
,
res
.
Path
()
.
Cid
()
.
String
())
}
}
...
...
@@ -92,7 +113,7 @@ func (tp *TestSuite) TestBlockGet(t *testing.T) {
t
.
Fatal
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
),
opt
.
Block
.
Hash
(
mh
.
KECCAK_512
,
-
1
))
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
),
opt
.
Block
.
Format
(
"raw"
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -130,7 +151,7 @@ func (tp *TestSuite) TestBlockRm(t *testing.T) {
t
.
Fatal
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
))
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
)
,
opt
.
Block
.
Format
(
"raw"
)
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -184,7 +205,7 @@ func (tp *TestSuite) TestBlockStat(t *testing.T) {
t
.
Fatal
(
err
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
))
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
)
,
opt
.
Block
.
Format
(
"raw"
)
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -211,7 +232,7 @@ func (tp *TestSuite) TestBlockPin(t *testing.T) {
t
.
Fatal
(
err
)
}
_
,
err
=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
))
_
,
err
=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
)
,
opt
.
Block
.
Format
(
"raw"
)
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -220,14 +241,19 @@ func (tp *TestSuite) TestBlockPin(t *testing.T) {
t
.
Fatal
(
"expected 0 pins"
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
),
opt
.
Block
.
Pin
(
true
))
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
),
opt
.
Block
.
Pin
(
true
),
opt
.
Block
.
Format
(
"raw"
),
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pins
,
err
:=
accPins
(
api
.
Pin
()
.
Ls
(
ctx
))
if
err
!=
nil
{
t
.
Skip
(
err
)
t
.
Fatal
(
err
)
}
if
len
(
pins
)
!=
1
{
t
.
Fatal
(
"expected 1 pin"
)
...
...
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