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-blockstore
Commits
9a3ae2aa
Commit
9a3ae2aa
authored
Feb 24, 2020
by
Andrey Petrov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test to maintain Put contract of calling Has first
parent
717588ff
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
blockstore_test.go
blockstore_test.go
+32
-0
No files found.
blockstore_test.go
View file @
9a3ae2aa
...
...
@@ -104,6 +104,38 @@ func TestPutThenGetSizeBlock(t *testing.T) {
}
}
type
countHasDS
struct
{
ds
.
Datastore
hasCount
int
}
func
(
ds
*
countHasDS
)
Has
(
key
ds
.
Key
)
(
exists
bool
,
err
error
)
{
ds
.
hasCount
+=
1
return
ds
.
Datastore
.
Has
(
key
)
}
func
TestPutUsesHas
(
t
*
testing
.
T
)
{
// Some datastores rely on the implementation detail that Put checks Has
// first, to avoid overriding existing objects' metadata. This test ensures
// that Blockstore continues to behave this way.
// Please ping https://github.com/ipfs/go-ipfs-blockstore/pull/47 if this
// behavior is being removed.
ds
:=
&
countHasDS
{
Datastore
:
ds
.
NewMapDatastore
(),
}
bs
:=
NewBlockstore
(
ds_sync
.
MutexWrap
(
ds
))
bl
:=
blocks
.
NewBlock
([]
byte
(
"some data"
))
if
err
:=
bs
.
Put
(
bl
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
bs
.
Put
(
bl
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
ds
.
hasCount
!=
2
{
t
.
Errorf
(
"Blockstore did not call Has before attempting Put, this breaks compatibility"
)
}
}
func
TestHashOnRead
(
t
*
testing
.
T
)
{
orginalDebug
:=
u
.
Debug
defer
(
func
()
{
...
...
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