Commit 323a2d54 authored by Jeromy's avatar Jeromy

blockservice.New doesnt need to return an error

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent 034441cf
......@@ -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.
......
......@@ -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()
}
......
......@@ -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
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment