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
00575204
Commit
00575204
authored
Feb 04, 2019
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
block put --pin option
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
e8196db4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
+49
-0
options/block.go
options/block.go
+11
-0
tests/block.go
tests/block.go
+38
-0
No files found.
options/block.go
View file @
00575204
...
...
@@ -10,6 +10,7 @@ type BlockPutSettings struct {
Codec
string
MhType
uint64
MhLength
int
Pin
bool
}
type
BlockRmSettings
struct
{
...
...
@@ -24,6 +25,7 @@ func BlockPutOptions(opts ...BlockPutOption) (*BlockPutSettings, cid.Prefix, err
Codec
:
""
,
MhType
:
mh
.
SHA2_256
,
MhLength
:
-
1
,
Pin
:
false
,
}
for
_
,
opt
:=
range
opts
{
...
...
@@ -105,6 +107,15 @@ func (blockOpts) Hash(mhType uint64, mhLen int) BlockPutOption {
}
}
// Pin is an option for Block.Put which specifies whether to (recursively) pin
// added blocks
func
(
blockOpts
)
Pin
(
pin
bool
)
BlockPutOption
{
return
func
(
settings
*
BlockPutSettings
)
error
{
settings
.
Pin
=
pin
return
nil
}
}
// Force is an option for Block.Rm which, when set to true, will ignore
// non-existing blocks
func
(
blockOpts
)
Force
(
force
bool
)
BlockRmOption
{
...
...
tests/block.go
View file @
00575204
...
...
@@ -26,6 +26,7 @@ func (tp *provider) TestBlock(t *testing.T) {
t
.
Run
(
"TestBlockGet"
,
tp
.
TestBlockGet
)
t
.
Run
(
"TestBlockRm"
,
tp
.
TestBlockRm
)
t
.
Run
(
"TestBlockStat"
,
tp
.
TestBlockStat
)
t
.
Run
(
"TestBlockPin"
,
tp
.
TestBlockPin
)
}
func
(
tp
*
provider
)
TestBlockPut
(
t
*
testing
.
T
)
{
...
...
@@ -203,3 +204,40 @@ func (tp *provider) TestBlockStat(t *testing.T) {
t
.
Error
(
"length doesn't match"
)
}
}
func
(
tp
*
provider
)
TestBlockPin
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
api
,
err
:=
tp
.
makeAPI
(
ctx
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
_
,
err
=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
pins
,
err
:=
api
.
Pin
()
.
Ls
(
ctx
);
err
!=
nil
||
len
(
pins
)
!=
0
{
t
.
Fatal
(
"expected 0 pins"
)
}
res
,
err
:=
api
.
Block
()
.
Put
(
ctx
,
strings
.
NewReader
(
`Hello`
),
opt
.
Block
.
Pin
(
true
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pins
,
err
:=
api
.
Pin
()
.
Ls
(
ctx
)
if
err
!=
nil
{
return
}
if
len
(
pins
)
!=
1
{
t
.
Fatal
(
"expected 1 pin"
)
}
if
pins
[
0
]
.
Type
()
!=
"recursive"
{
t
.
Error
(
"expected a recursive pin"
)
}
if
pins
[
0
]
.
Path
()
.
String
()
!=
res
.
Path
()
.
String
()
{
t
.
Error
(
"pin path didn't match"
)
}
}
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