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-ds-flatfs
Commits
9ff7509b
Commit
9ff7509b
authored
Jul 06, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a few tests
parent
da9871df
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
flatfs_test.go
flatfs_test.go
+44
-0
No files found.
flatfs_test.go
View file @
9ff7509b
package
flatfs_test
import
(
"bytes"
"encoding/base32"
"io/ioutil"
"os"
...
...
@@ -320,6 +321,49 @@ func TestQuerySimple(t *testing.T) {
}
}
func
TestBatchPut
(
t
*
testing
.
T
)
{
temp
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
fs
,
err
:=
flatfs
.
New
(
temp
,
2
)
if
err
!=
nil
{
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
}
batch
:=
fs
.
Batch
()
r
:=
rand
.
New
()
var
blocks
[][]
byte
var
keys
[]
datastore
.
Key
for
i
:=
0
;
i
<
20
;
i
++
{
blk
:=
make
([]
byte
,
256
*
1024
)
r
.
Read
(
blk
)
blocks
=
append
(
blocks
,
blk
)
key
:=
datastore
.
NewKey
(
base32
.
StdEncoding
.
EncodeToString
(
blk
[
:
8
]))
keys
=
append
(
keys
,
key
)
err
:=
batch
.
Put
(
key
,
blk
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
err
=
batch
.
Commit
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
i
,
k
:=
range
keys
{
blk
,
err
:=
fs
.
Get
(
k
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
(
blk
.
([]
byte
),
blocks
[
i
])
{
t
.
Fatal
(
"blocks not correct!"
)
}
}
}
func
BenchmarkConsecutivePut
(
b
*
testing
.
B
)
{
r
:=
rand
.
New
()
var
blocks
[][]
byte
...
...
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