1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 05:52:20 +08:00

add test for reprovider and slight refactor

This commit is contained in:
Jeromy
2015-01-14 22:14:52 +00:00
parent f068c89147
commit a7650b259d
3 changed files with 56 additions and 5 deletions

View File

@ -0,0 +1,50 @@
package reprovide_test
import (
"testing"
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/go-datastore"
dssync "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
blocks "github.com/jbenet/go-ipfs/blocks"
blockstore "github.com/jbenet/go-ipfs/blocks/blockstore"
mock "github.com/jbenet/go-ipfs/routing/mock"
testutil "github.com/jbenet/go-ipfs/util/testutil"
. "github.com/jbenet/go-ipfs/exchange/reprovide"
)
func TestReprovide(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
mrserv := mock.NewServer()
idA := testutil.RandIdentityOrFatal(t)
idB := testutil.RandIdentityOrFatal(t)
clA := mrserv.Client(idA)
clB := mrserv.Client(idB)
bstore := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore()))
blk := blocks.NewBlock([]byte("this is a test"))
bstore.Put(blk)
reprov := NewReprovider(clA, bstore)
reprov.Reprovide(ctx)
provs, err := clB.FindProviders(ctx, blk.Key())
if err != nil {
t.Fatal(err)
}
if len(provs) == 0 {
t.Fatal("Should have gotten a provider")
}
if provs[0].ID != idA.ID() {
t.Fatal("Somehow got the wrong peer back as a provider.")
}
}