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
6486d677
Unverified
Commit
6486d677
authored
Feb 25, 2020
by
Steven Allen
Committed by
GitHub
Feb 25, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #47 from shazow/blockstore-put-tst
Add test to maintain Put contract of calling Has first
parents
717588ff
9a3ae2aa
Changes
1
Hide 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 @
6486d677
...
...
@@ -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