Commit e66cbaca authored by Jeromy's avatar Jeromy

removed error from return type of blocks.NewBlock()

parent 3d12baae
......@@ -9,7 +9,7 @@ import (
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
"github.com/jbenet/go-ipfs/blocks"
blocks "github.com/jbenet/go-ipfs/blocks"
bstore "github.com/jbenet/go-ipfs/blockstore"
exchange "github.com/jbenet/go-ipfs/exchange"
notifications "github.com/jbenet/go-ipfs/exchange/bitswap/notifications"
......@@ -18,7 +18,6 @@ import (
peer "github.com/jbenet/go-ipfs/peer"
mock "github.com/jbenet/go-ipfs/routing/mock"
util "github.com/jbenet/go-ipfs/util"
testutil "github.com/jbenet/go-ipfs/util/testutil"
)
func TestGetBlockTimeout(t *testing.T) {
......@@ -30,7 +29,7 @@ func TestGetBlockTimeout(t *testing.T) {
self := g.Next()
ctx, _ := context.WithTimeout(context.Background(), time.Nanosecond)
block := testutil.NewBlockOrFail(t, "block")
block := blocks.NewBlock([]byte("block"))
_, err := self.exchange.Block(ctx, block.Key())
if err != context.DeadlineExceeded {
......@@ -44,7 +43,7 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) {
rs := mock.VirtualRoutingServer()
g := NewSessionGenerator(net, rs)
block := testutil.NewBlockOrFail(t, "block")
block := blocks.NewBlock([]byte("block"))
rs.Announce(&peer.Peer{}, block.Key()) // but not on network
solo := g.Next()
......@@ -63,15 +62,15 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
net := tn.VirtualNetwork()
rs := mock.VirtualRoutingServer()
block := testutil.NewBlockOrFail(t, "block")
block := blocks.NewBlock([]byte("block"))
g := NewSessionGenerator(net, rs)
hasBlock := g.Next()
if err := hasBlock.blockstore.Put(block); err != nil {
if err := hasBlock.blockstore.Put(*block); err != nil {
t.Fatal(err)
}
if err := hasBlock.exchange.HasBlock(context.Background(), block); err != nil {
if err := hasBlock.exchange.HasBlock(context.Background(), *block); err != nil {
t.Fatal(err)
}
......@@ -93,7 +92,7 @@ func TestSwarm(t *testing.T) {
net := tn.VirtualNetwork()
rs := mock.VirtualRoutingServer()
sg := NewSessionGenerator(net, rs)
bg := NewBlockGenerator(t)
bg := NewBlockGenerator()
t.Log("Create a ton of instances, and just a few blocks")
......@@ -154,7 +153,7 @@ func TestSendToWantingPeer(t *testing.T) {
net := tn.VirtualNetwork()
rs := mock.VirtualRoutingServer()
sg := NewSessionGenerator(net, rs)
bg := NewBlockGenerator(t)
bg := NewBlockGenerator()
me := sg.Next()
w := sg.Next()
......@@ -212,20 +211,17 @@ func TestSendToWantingPeer(t *testing.T) {
}
}
func NewBlockGenerator(t *testing.T) BlockGenerator {
return BlockGenerator{
T: t,
}
func NewBlockGenerator() BlockGenerator {
return BlockGenerator{}
}
type BlockGenerator struct {
*testing.T // b/c block generation can fail
seq int
seq int
}
func (bg *BlockGenerator) Next() blocks.Block {
bg.seq++
return testutil.NewBlockOrFail(bg.T, string(bg.seq))
return *blocks.NewBlock([]byte(string(bg.seq)))
}
func (bg *BlockGenerator) Blocks(n int) []*blocks.Block {
......
......@@ -32,19 +32,16 @@ func New() *message {
return new(message)
}
func newMessageFromProto(pbm PBMessage) (BitSwapMessage, error) {
func newMessageFromProto(pbm PBMessage) BitSwapMessage {
m := New()
for _, s := range pbm.GetWantlist() {
m.AppendWanted(u.Key(s))
}
for _, d := range pbm.GetBlocks() {
b, err := blocks.NewBlock(d)
if err != nil {
return nil, err
}
b := blocks.NewBlock(d)
m.AppendBlock(*b)
}
return m, nil
return m
}
// TODO(brian): convert these into keys
......@@ -70,10 +67,7 @@ func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) {
if err := proto.Unmarshal(nmsg.Data(), pb); err != nil {
return nil, err
}
m, err := newMessageFromProto(*pb)
if err != nil {
return nil, err
}
m := newMessageFromProto(*pb)
return m, nil
}
......
......@@ -4,9 +4,9 @@ import (
"bytes"
"testing"
"github.com/jbenet/go-ipfs/blocks"
peer "github.com/jbenet/go-ipfs/peer"
u "github.com/jbenet/go-ipfs/util"
testutil "github.com/jbenet/go-ipfs/util/testutil"
)
func TestAppendWanted(t *testing.T) {
......@@ -26,10 +26,7 @@ func TestNewMessageFromProto(t *testing.T) {
if !contains(protoMessage.Wantlist, str) {
t.Fail()
}
m, err := newMessageFromProto(*protoMessage)
if err != nil {
t.Fatal(err)
}
m := newMessageFromProto(*protoMessage)
if !contains(m.ToProto().GetWantlist(), str) {
t.Fail()
}
......@@ -43,8 +40,8 @@ func TestAppendBlock(t *testing.T) {
m := New()
for _, str := range strs {
block := testutil.NewBlockOrFail(t, str)
m.AppendBlock(block)
block := blocks.NewBlock([]byte(str))
m.AppendBlock(*block)
}
// assert strings are in proto message
......@@ -134,10 +131,10 @@ func TestToNetFromNetPreservesWantList(t *testing.T) {
func TestToAndFromNetMessage(t *testing.T) {
original := New()
original.AppendBlock(testutil.NewBlockOrFail(t, "W"))
original.AppendBlock(testutil.NewBlockOrFail(t, "E"))
original.AppendBlock(testutil.NewBlockOrFail(t, "F"))
original.AppendBlock(testutil.NewBlockOrFail(t, "M"))
original.AppendBlock(*blocks.NewBlock([]byte("W")))
original.AppendBlock(*blocks.NewBlock([]byte("E")))
original.AppendBlock(*blocks.NewBlock([]byte("F")))
original.AppendBlock(*blocks.NewBlock([]byte("M")))
p := &peer.Peer{ID: []byte("X")}
netmsg, err := original.ToNet(p)
......
......@@ -6,25 +6,23 @@ import (
"time"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
testutil "github.com/jbenet/go-ipfs/util/testutil"
blocks "github.com/jbenet/go-ipfs/blocks"
)
func TestPublishSubscribe(t *testing.T) {
blockSent := testutil.NewBlockOrFail(t, "Greetings from The Interval")
blockSent := blocks.NewBlock([]byte("Greetings from The Interval"))
n := New()
defer n.Shutdown()
ch := n.Subscribe(context.Background(), blockSent.Key())
n.Publish(blockSent)
n.Publish(*blockSent)
blockRecvd, ok := <-ch
if !ok {
t.Fail()
}
assertBlocksEqual(t, blockRecvd, blockSent)
assertBlocksEqual(t, blockRecvd, *blockSent)
}
......@@ -35,7 +33,7 @@ func TestCarryOnWhenDeadlineExpires(t *testing.T) {
n := New()
defer n.Shutdown()
block := testutil.NewBlockOrFail(t, "A Missed Connection")
block := blocks.NewBlock([]byte("A Missed Connection"))
blockChannel := n.Subscribe(fastExpiringCtx, block.Key())
assertBlockChannelNil(t, blockChannel)
......
......@@ -4,9 +4,9 @@ import (
"strings"
"testing"
blocks "github.com/jbenet/go-ipfs/blocks"
message "github.com/jbenet/go-ipfs/exchange/bitswap/message"
peer "github.com/jbenet/go-ipfs/peer"
testutil "github.com/jbenet/go-ipfs/util/testutil"
)
type peerAndStrategist struct {
......@@ -30,7 +30,7 @@ func TestConsistentAccounting(t *testing.T) {
m := message.New()
content := []string{"this", "is", "message", "i"}
m.AppendBlock(testutil.NewBlockOrFail(t, strings.Join(content, " ")))
m.AppendBlock(*blocks.NewBlock([]byte(strings.Join(content, " "))))
sender.MessageSent(receiver.Peer, m)
receiver.MessageReceived(sender.Peer, m)
......@@ -57,7 +57,7 @@ func TestBlockRecordedAsWantedAfterMessageReceived(t *testing.T) {
beggar := newPeerAndStrategist("can't be chooser")
chooser := newPeerAndStrategist("chooses JIF")
block := testutil.NewBlockOrFail(t, "data wanted by beggar")
block := blocks.NewBlock([]byte("data wanted by beggar"))
messageFromBeggarToChooser := message.New()
messageFromBeggarToChooser.AppendWanted(block.Key())
......
......@@ -5,10 +5,10 @@ import (
"testing"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
blocks "github.com/jbenet/go-ipfs/blocks"
bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
peer "github.com/jbenet/go-ipfs/peer"
testutil "github.com/jbenet/go-ipfs/util/testutil"
)
func TestSendRequestToCooperativePeer(t *testing.T) {
......@@ -33,7 +33,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
// TODO test contents of incoming message
m := bsmsg.New()
m.AppendBlock(testutil.NewBlockOrFail(t, expectedStr))
m.AppendBlock(*blocks.NewBlock([]byte(expectedStr)))
return from, m
}))
......@@ -41,7 +41,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
t.Log("Build a message and send a synchronous request to recipient")
message := bsmsg.New()
message.AppendBlock(testutil.NewBlockOrFail(t, "data"))
message.AppendBlock(*blocks.NewBlock([]byte("data")))
response, err := initiator.SendRequest(
context.Background(), &peer.Peer{ID: idOfRecipient}, message)
if err != nil {
......@@ -77,7 +77,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
*peer.Peer, bsmsg.BitSwapMessage) {
msgToWaiter := bsmsg.New()
msgToWaiter.AppendBlock(testutil.NewBlockOrFail(t, expectedStr))
msgToWaiter.AppendBlock(*blocks.NewBlock([]byte(expectedStr)))
return fromWaiter, msgToWaiter
}))
......@@ -105,7 +105,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
}))
messageSentAsync := bsmsg.New()
messageSentAsync.AppendBlock(testutil.NewBlockOrFail(t, "data"))
messageSentAsync.AppendBlock(*blocks.NewBlock([]byte("data")))
errSending := waiter.SendMessage(
context.Background(), &peer.Peer{ID: idOfResponder}, messageSentAsync)
if errSending != nil {
......
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