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-blockservice
Commits
323a2d54
Commit
323a2d54
authored
Aug 14, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
blockservice.New doesnt need to return an error
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
034441cf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
22 deletions
+6
-22
blockservice.go
blockservice.go
+2
-6
test/blocks_test.go
test/blocks_test.go
+2
-6
test/mock.go
test/mock.go
+2
-10
No files found.
blockservice.go
View file @
323a2d54
...
...
@@ -5,7 +5,6 @@ package blockservice
import
(
"errors"
"fmt"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
blocks
"github.com/ipfs/go-ipfs/blocks"
...
...
@@ -48,10 +47,7 @@ type BlockService struct {
}
// NewBlockService creates a BlockService with given datastore instance.
func
New
(
bs
blockstore
.
Blockstore
,
rem
exchange
.
Interface
)
(
*
BlockService
,
error
)
{
if
bs
==
nil
{
return
nil
,
fmt
.
Errorf
(
"BlockService requires valid blockstore"
)
}
func
New
(
bs
blockstore
.
Blockstore
,
rem
exchange
.
Interface
)
*
BlockService
{
if
rem
==
nil
{
log
.
Warning
(
"blockservice running in local (offline) mode."
)
}
...
...
@@ -60,7 +56,7 @@ func New(bs blockstore.Blockstore, rem exchange.Interface) (*BlockService, error
Blockstore
:
bs
,
Exchange
:
rem
,
worker
:
worker
.
NewWorker
(
rem
,
wc
),
}
,
nil
}
}
// AddBlock adds a particular block to the service, Putting it into the datastore.
...
...
test/blocks_test.go
View file @
323a2d54
...
...
@@ -19,11 +19,7 @@ import (
func
TestBlocks
(
t
*
testing
.
T
)
{
bstore
:=
blockstore
.
NewBlockstore
(
dssync
.
MutexWrap
(
ds
.
NewMapDatastore
()))
bs
,
err
:=
New
(
bstore
,
offline
.
Exchange
(
bstore
))
if
err
!=
nil
{
t
.
Error
(
"failed to construct block service"
,
err
)
return
}
bs
:=
New
(
bstore
,
offline
.
Exchange
(
bstore
))
defer
bs
.
Close
()
b
:=
blocks
.
NewBlock
([]
byte
(
"beep boop"
))
...
...
@@ -63,7 +59,7 @@ func TestBlocks(t *testing.T) {
}
func
TestGetBlocksSequential
(
t
*
testing
.
T
)
{
var
servs
=
Mocks
(
t
,
4
)
var
servs
=
Mocks
(
4
)
for
_
,
s
:=
range
servs
{
defer
s
.
Close
()
}
...
...
test/mock.go
View file @
323a2d54
...
...
@@ -8,12 +8,8 @@ import (
delay
"github.com/ipfs/go-ipfs/thirdparty/delay"
)
type
fataler
interface
{
Fatal
(
args
...
interface
{})
}
// Mocks returns |n| connected mock Blockservices
func
Mocks
(
t
fataler
,
n
int
)
[]
*
BlockService
{
func
Mocks
(
n
int
)
[]
*
BlockService
{
net
:=
tn
.
VirtualNetwork
(
mockrouting
.
NewServer
(),
delay
.
Fixed
(
0
))
sg
:=
bitswap
.
NewTestSessionGenerator
(
net
)
...
...
@@ -21,11 +17,7 @@ func Mocks(t fataler, n int) []*BlockService {
var
servs
[]
*
BlockService
for
_
,
i
:=
range
instances
{
bserv
,
err
:=
New
(
i
.
Blockstore
(),
i
.
Exchange
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
servs
=
append
(
servs
,
bserv
)
servs
=
append
(
servs
,
New
(
i
.
Blockstore
(),
i
.
Exchange
))
}
return
servs
}
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